8

I'm fairly new to Latex and am trying to typeset some finance notes. How do I go about angling text or math equations above a timeline made using Tikz?

This is what I have:

\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] {[P+(n-2)Q]};
   \draw (10,0) node[below=3pt] {$T_n$} node[above=3pt] {[P+(n-1)Q]};

   \end{tikzpicture}

And this is what comes out:enter image description here

Is there a way for me to angle the formulas at the end so that they don't overlap?

1
  • Welcome to TeX - LaTeX! Simplest would be to simply raise one of the last two formulae, replacing above=3pt by some large value. Sep 8 '17 at 10:31
15

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

7

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

4

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.