3

I am trying to re-create the following horizontal timeline chart. I found some related examples, but nothing really close to do what I need (also perhaps for lack of correct naming of the chart itself). Thanks for any input on this.

enter image description here

UPDATE:

This is what I managed to produce (source): enter image description here

by using:

\documentclass[a4paper,10pt]{article}

\usepackage{tikz}
\usepackage{verbatim}
\usepackage[active,tightpage]{preview}
\PreviewEnvironment{tikzpicture}
\setlength\PreviewBorder{5pt}%
\usetikzlibrary{arrows,chains,matrix,positioning,scopes}
\makeatletter
\tikzset{join/.code=\tikzset{after node path={%
\ifx\tikzchainprevious\pgfutil@empty\else(\tikzchainprevious)%
edge[every join]#1(\tikzchaincurrent)\fi}}}
\makeatother
\tikzset{>=stealth',every on chain/.append style={join},
         every join/.style={->}}
\tikzstyle{labeled}=[execute at begin node=$\scriptstyle,
   execute at end node=$]
%
\begin{document}
\begin{tikzpicture}
  \matrix (m) [matrix of math nodes, row sep=3em, column sep=3em]
    { group \, 1 & N & \phantom{N} & M &  S,M  & \phantom{S,M} \\
      group \, 2 & N & S,M &  & \phantom{S,M} & \phantom{S,M} \\ };
  { [start chain] \chainin (m-1-2);
    \chainin (m-1-4); %[join={node[above,labeled] {\psi}}];
    \chainin (m-1-5); 
    \chainin (m-1-6);}

   { [start chain] \chainin (m-2-2);
    \chainin (m-2-3); 
        { [start branch=A] \chainin (m-1-3);}
    \chainin (m-2-6);}
\end{tikzpicture}
\end{document}

The bottom timeline is still giving me issues. Also, I am not sure how to get the second upwards arrow. Thanks for your help.

  • 1
    When looking at examples, don't look only for complete examples that look very similar. Try finding examples that contain individual elements of what you're after, understanding how they work, and combining them. If you get stuck, post the code of what you achieved, and ask how to move forward. If you figure out how to place text at a given coordinate, and how to draw an arrow, you would be able to do alot of that. (Question like this, asking for code to reproduce an image, are sometimes answered, sometimes not, depending on whether someone likes the challenge and is in the right mood.) – Torbjørn T. Dec 16 '17 at 11:06
  • Look for tikz package: arrow between (x,y) [initial and final] :command: \draw[->] (x_init,y_init)--(x_fin,y_fin); symbol or phrase on point (x1,y1) \node at (x1,y1) {MySym}; simple line like arrow but \draw instead of \draw[->] – koleygr Dec 16 '17 at 11:08
  • You could add another row to the matrix for the bottom line, maybe? – cfr Dec 16 '17 at 16:59
4

Here is one way of achieving something like that. As suggested by cfr, a third row is added to the \matrix, and the timeline is drawn using the nodes in that as reference. There are some alterations to the matrix code, indicated by columns. Some of this uses the -| syntax for coordinates (see TikZ: What EXACTLY does the the |- notation for arrows do?).

output of code

\documentclass[border=5mm]{standalone}
\usepackage{amsmath}
\usepackage{tikz}
\usetikzlibrary{arrows,chains,matrix,positioning,scopes}
\makeatletter
\tikzset{
  join/.code=\tikzset{after node path={%
      \ifx\tikzchainprevious\pgfutil@empty\else(\tikzchainprevious)%
      edge[every join]#1(\tikzchaincurrent)\fi}
  },
  >=stealth',
  every on chain/.append style={join},
  every join/.style={->},
  labeled/.style={
     execute at begin node=$\scriptstyle,
     execute at end node=$
  }
}
%
\begin{document}
\begin{tikzpicture}
  \matrix (m) [
      matrix of math nodes,
      nodes in empty cells, % adds nodes in cells without content
      row sep=3em, column sep=4em,
      nodes={font={\vphantom{S,}}}, % to account for missing commas, no need for \phantoms
      row 3/.style={text height=0pt,text depth=0pt} % to reduce height of nodes in third row
    ]
    % note \text for first column
    % added third row as suggested by cfr
    { \text{group 1} &[-2em] N &      & M  &  S,M   &   &  \\
      \text{group 2} &       N & S,M  &    &        &   &  \\[-2em] % reduce space between second and third row
      &&&&&& \\
    };
  { [start chain]
    \chainin (m-1-2);
    \chainin (m-1-4); %[join={node[above,labeled] {\psi}}];
    \chainin (m-1-5); 
    \chainin (m-1-7);}

   { [start chain]
    \chainin (m-2-2);
    \chainin (m-2-3); 
    \chainin (m-2-7);}

    % draw dashed vertical lines
    \draw [densely dashed,->] (m-2-3)          -- (m-2-3  |- m-1-1);
    \draw [densely dashed,->] (m-1-4 |- m-2-1) -- (m-1-4);

    % draw arrow for timeline
    \draw [->] (m-3-1 -| m-2-1.east) -- (m-3-7);

    % draw ticks and add labels
    \foreach [count=\i from 2] \txt in {
       Before\\Sept. 2013,
       Sept. 2013,
       Jan. 2014,
       March 2015,
       After\\March 2015} {
         \draw ([yshift=2pt]m-3-\i.center) -- ++(0,-4pt)
            node [below,align=center,font=\footnotesize] {\txt};
      }
\end{tikzpicture}
\end{document}
  • This is an excellent answer, both in the final result and in the clarity of coding. Thanks so much for the help. – Stefano Lombardi Dec 17 '17 at 13:26

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.