Angling text above a Tikz timeline

Rotating only two labels can be quite ugly, you may want to rotate all the labels the same way.

\documentclass[12pt,a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage{graphicx,tikz}
\begin{document}
\begin{tikzpicture}[scale=1,rotLabel/.style={above,rotate=30,anchor=200}]
 % draw horizontal line 
  \draw (0,0) -- (10,0);
  % draw vertical lines
   \foreach \x in {0,1.5,3,4.5,8.5,10}
   \draw (\x cm,3pt) -- (\x cm,-3pt);
    % draw nodes
   \draw (0,0) node[below=3pt] {$T_0$ } node[rotLabel] {};
   \draw (1.5,0) node[below=3pt] {$T_1$} node[rotLabel] {P};
   \draw (3,0) node[below=3pt] {$T_2$} node[rotLabel] {P+Q};
   \draw (4.5,0) node[below=3pt] {$T_3$} node[rotLabel] {P+2Q};
   \draw (8.5,0) node[below=3pt] {$T_{n-1}$} node[rotLabel] {[P+(n-2)Q]};
   \draw (10,0) node[below=3pt] {$T_n$} node[rotLabel] {[P+(n-1)Q]};
   \end{tikzpicture}
\end{document}

enter image description here

Another option is to raise one of the last two labels a bit. Only the last label is changed like this (all other above=3pt become just above and all below=3pt become just below):

\draw (10,0) node[below=3pt] {$T_n$} node[above=15pt] {[P+(n-1)Q]};
\draw[<-] (10,0.2) -- ++(0,1em);

enter image description here


You could use rotate, anchoring south east the nodes you want to rotate.

Edit: of course, if you prefer, you could rotate all the nodes.

\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
% draw horizontal line   
\draw (0,0) -- (10,0);

% draw vertical lines
\foreach \x in {0,1.5,3,4.5,8.5,10}
\draw (\x cm,3pt) -- (\x cm,-3pt);

% draw nodes
\draw (0,0) node[below=3pt] {$T_0$ } node[above=3pt] {};
\draw (1.5,0) node[below=3pt] {$T_1$} node[above=3pt] {P};
\draw (3,0) node[below=3pt] {$T_2$} node[above=3pt] {P+Q};
\draw (4.5,0) node[below=3pt] {$T_3$} node[above=3pt] {P+2Q};
\draw (8.5,0) node[below=3pt] {$T_{n-1}$} node[above=3pt, anchor= south east, rotate=-45] {[P+(n-2)Q]};
\draw (10,0) node[below=3pt] {$T_n$} node[above=3pt, anchor= south east, rotate=-45] {[P+(n-1)Q]};

\end{tikzpicture}

\vspace{30pt}As AboAmmar said, you could also rotate all the labels:

\begin{tikzpicture}[mylabel/.style={above=3pt, anchor= south east, rotate=-45}]
% draw horizontal line   
\draw (0,0) -- (10,0);

% draw vertical lines
\foreach \x in {0,1.5,3,4.5,8.5,10}
\draw (\x cm,3pt) -- (\x cm,-3pt);

% draw nodes
\draw (0,0) node[below=3pt] {$T_0$ } node[mylabel] {};
\draw (1.5,0) node[below=3pt] {$T_1$} node[mylabel] {P};
\draw (3,0) node[below=3pt] {$T_2$} node[mylabel] {P+Q};
\draw (4.5,0) node[below=3pt] {$T_3$} node[mylabel] {P+2Q};
\draw (8.5,0) node[below=3pt] {$T_{n-1}$} node[mylabel] {[P+(n-2)Q]};
\draw (10,0) node[below=3pt] {$T_n$} node[mylabel] {[P+(n-1)Q]};

\end{tikzpicture}
\end{document}

enter image description here


a modification of first example of AboAmmar answer ... used are two loops, math environments for above labels ...

\documentclass[12pt,a4paper]{article}
\usepackage{tikz}
\usetikzlibrary{positioning}

\begin{document}
    \begin{tikzpicture}[node distance =2mm]
% draw horizontal line
  \draw (0,0) -- (10,0);
% draw vertical lines
\foreach \x/\j [count=\xx] in {0/0, 1.5/1, 3/2, 4.5/,8.5/{n-1}, 10/n}
   \draw (\x,3pt) -- +(0,-6pt) node (q\xx) [below] {$T_{\j}$};
\foreach \x [count=\xx from 2] in {P, P+Q, P+2Q, P+(n-2)Q, P+(n-2)Q}
    \node [above=of q\xx, rotate=45, anchor=south west] {$\mathsf{\x}$};
   \end{tikzpicture}
\end{document}

enter image description here