1

I've created a figure that displays a "timeline" that contains specific points as well as ranges. The only thing that I want to add (but don't know how) are dots/circles/squares at the points (at 0, theta * s, theta*s+w and z). Also, I would like to center the timeline. When I wrap the tikzpicture in the figure environment, no output is created.

This is my code:

\documentclass{article}
    \usepackage{tikz}
\usetikzlibrary{arrows,positioning,decorations.pathreplacing}

    \begin{document}

\begin{tikzpicture}[
    every node/.style = {align=center},
          Line/.style = {-angle 90, shorten >=2pt},
    Brace/.style args = {#1}{semithick, decorate, decoration={brace,#1,raise=20pt,
                             pre=moveto,pre length=2pt,post=moveto,post length=2pt,}},
            ys/.style = {yshift=#1}
                    ]
\linespread{0.8}                    
\coordinate (a) at (0,0);
\coordinate[right=30mm of a]    (b);
\coordinate[right=30mm of b]    (c);
\coordinate[right= 20mm of c]    (d);
\coordinate[right=24mm of d]    (e);
\coordinate[right= 5mm of e]    (f);
\coordinate[right=22mm of f]    (g);

\draw[Line] (a) -- (g) node[right] {x};

\draw[Brace=mirror] (a) -- node[below=20pt] {Compensation} (b);
\draw[Brace=mirror] (b) -- node[below=20pt] {Gift} (d);

\draw ([ys=0mm] a) node[below] {0} -- (a);
\draw ([ys=0mm] b) node[below] {$\theta s$} -- (b);
\draw[Line] ([ys=10mm]  c) node[above] {$\delta$} -- (c);
\draw[Line] ([ys=10mm]  d) node[above] {$x(\delta)$} -- (d);
\draw ([ys=0mm]  d) node[below] {$\theta s + w$} -- (d);

\draw ([ys=0mm]  f) node[below] {z} -- (f);
\end{tikzpicture} 

\end{document}

This is my current output:

enter image description here

2

I really don't know tikz, but just playing with it, I came up with this. It involved adding * specs to the Line \draw macros, changing the default shorten value, modifying it as necessary.

EDITED for centering (an oversized image), using a center environment plus \makebox[\textwidth]{}.

\documentclass{article}
    \usepackage{tikz}
\usetikzlibrary{arrows,positioning,decorations.pathreplacing}
\usepackage{lipsum}
\begin{document}
\lipsum[1]
\begin{center}
\makebox[\textwidth]{\begin{tikzpicture}[
    every node/.style = {align=center},
          Line/.style = {-angle 90, shorten <=-2pt},
    Brace/.style args = {#1}{semithick, decorate, decoration={brace,#1,raise=20pt,
                             pre=moveto,pre length=2pt,post=moveto,post length=2pt,}},
            ys/.style = {yshift=#1}
                    ]
\linespread{0.8}                    
\coordinate (a) at (0,0);
\coordinate[right=30mm of a]    (b);
\coordinate[right=30mm of b]    (c);
\coordinate[right= 20mm of c]    (d);
\coordinate[right=24mm of d]    (e);
\coordinate[right= 5mm of e]    (f);
\coordinate[right=22mm of f]    (g);

\draw[Line,*-] (a) --  (g) node[right] {$x$};
\draw[Line, *-] (b) --  (c) ;
\draw[Line, *-] (d) --  (e) ;
\draw[Line, *-] (f) --  (g) ;

\draw[Brace=mirror] (a) -- node[below=20pt] {Compensation} (b);
\draw[Brace=mirror] (b) -- node[below=20pt] {Gift} (d);

\draw ([ys=0mm] a) node[below] {0} -- (a);
\draw ([ys=0mm] b) node[below] {$\theta s$} -- (b);
\draw[Line, shorten >=4pt] ([ys=10mm]  c) node[above] {$\delta$} -- (c);
\draw[Line, shorten >=4pt] ([ys=10mm]  d) node[above] {$x(\delta)$} -- (d);
\draw ([ys=0mm]  d) node[below] {$\theta s + w$} -- (d);

\draw ([ys=0mm]  f) node[below] {$z$} -- (f);
\end{tikzpicture}}
\end{center}
\lipsum[2]
\end{document}

enter image description here

  • Brilliant! Also tried to add "*" for the dots but wasn't successful. Thx again! I tried to add a \caption{} and a \label{} between \end{tikzpicture}} and \end{center} but no caption or label were generated. Where in the code do I implement the label and the caption? – Saud Apr 8 '16 at 11:53

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.