1

Building on the nice answer to this question, I would like to modify the boxes right to the timeline to show a label (instead of the year) that I would like to specify right after the text of each entry, maybe in another {...}. Is this possible? I've seen the chains manual, but this one seems to require quite a bit more knowledge.

\documentclass[tikz]{standalone}
\usetikzlibrary{chains}
\makeatletter
\tikzset{west below/.code=\tikz@lib@place@handle@{#1}{north west}{0}{-1}{south west}{1}}
\makeatother
\tikzset{
  typnode/.style={anchor=north west, text width=12cm, inner sep=0mm},
  data/.style={draw=gray, rectangle, font=\scriptsize, inner sep=0.5mm},
}
\begin{document}
\begin{tikzpicture}[x=1cm, y=-7mm]{
%draw horizontal line
\foreach \xValue in {0,5}
  \path (\xValue,0) edge[-latex] ++(0,6.5)
                    edge[dashed] ++ (down:1);

%%draw years
\foreach \year in {1995,2000}{ 
  \node[left=2pt,anchor=east,xshift=0,font=\scriptsize] at (0,\year - 1995) {$\year$}; 
}
\foreach \year in {1995,1996,...,2000}{ 
  \draw (-0.1,\year-1995) -- (0.1,\year-1995); \draw (0,\year-1995+.5) -- (0.1,\year-1995+.5);
}

\begin{scope}[start chain=ch1 going west below, node distance=+1em]
\foreach \Year/\Text in {%
    1995/{King James VI of Scotland ascends to the English throne, becoming James I of England and uniting the crowns - but not the parliaments - of the two kingdoms},
    1995.01/{King James VI of Scotland ascends to the English throne, becoming James I of England and uniting the crowns - but not the parliaments - of the two kingdoms}
    }{
  \node[typnode, at=(right:3cm), on chain=ch1, alias=Text] {\Text};
  \node[data,    base left=+2em of Text, alias=Year] {\Year};
  \draw     (Year.west) -- ++(left:3mm)
                        -- ([shift=(right:3mm)] 0,{(\Year-1995)/10})
                        --                     (0,{(\Year-1995)/10});
}
\end{scope}
}
\end{tikzpicture}
\end{document}

There is also a second vertical line crossing the text that I haven't figured out to remove and when I try to include it in a documentclass[article], I get 1.5 empty pages upfront for a reason I don't understand, but these are secondary questions.

4
  • 2
    The second vertical line comes from the second iteration of the first loop. The linked Q/A used the value 34, I don't know why OP had that in his original code. Just remove the 5 and/or replace the loop and substitute 0 for \xValue. The 1.5 empty pages I can't reproduce. You can just do \node[ base right=of Year] {\Label};. You just need to include the \Label like \Year and \Text in the \foreach loop. Commented Jun 12, 2023 at 16:51
  • 1
    That should be right=of Text not Year. Commented Jun 13, 2023 at 0:14
  • That solves it, the empty pages problem is specific to my document and vanishes if put the timeline in a figure environment. Thanks!
    – bolzep
    Commented Jun 15, 2023 at 13:39
  • @Qrrbrbirlbel Answer or close?
    – cfr
    Commented Aug 13, 2023 at 15:22

1 Answer 1

2

The second vertical line comes from the second iteration of the first loop. The linked Q/A used the value 34, I don't know why OP had that in his original code. Just remove the 5 and/or replace the loop and substitute 0 for \xValue (which I did in the code below).

You can just do

\node[base right=of Text] {\Label};

after you add \Label to the loop variables.

Notes:

  • 1995.011995.12 will not be recognized as a linear progession through the years. You will need some adjustments to allow real dates.
  • If the \Label will be multiline it might be higher than the \Year node and thus produce bad results when the chain isn't adjusted for that.

Code

\documentclass[tikz]{standalone}
\usetikzlibrary{chains}
\makeatletter
\tikzset{west below/.code=\tikz@lib@place@handle@{#1}{north west}{0}{-1}{south west}{1}}
\makeatother
\tikzset{
  typnode/.style={anchor=north west, text width=12cm, inner sep=0mm},
  data/.style={draw=gray, rectangle, font=\scriptsize, inner sep=0.5mm}}
\begin{document}
\begin{tikzpicture}[x=1cm, y=-7mm]
%draw horizontal line
\path (0,0) edge[-latex] ++(0,6.5)
            edge[dashed] ++ (down:1);

%%draw years
\foreach \year in {1995,2000}
  \node[left=2pt, font=\scriptsize] at (0,\year-1995) {$\year$};

\foreach \year in {1995,1996, ..., 2000}
  \draw (-0.1,\year-1995   ) -- (0.1,\year-1995   )
        ( 0,  \year-1995+.5) -- (0.1,\year-1995+.5);

\begin{scope}[start chain=ch1 going west below, node distance=+1em]
\foreach \Year/\Label/\Text in {
    1995/{A Label for the first Entry}/{
      King James VI of Scotland ascends to the English throne, becoming James I
      of England and uniting the crowns -- but not the parliaments --
      of the two kingdoms},
    1995.01/{A Label for the second Entry}/{
      King James VI of Scotland ascends to the English throne, becoming James I
      of England and uniting the crowns -- but not the parliaments --
      of the two kingdoms}%
    }{
  \node[typnode, at=(right:3cm), on chain=ch1, alias=Text] {\Text};
  \node[data,    base left=+2em of Text, alias=Year] {\Year};
  \node[base right=of Text]{\Label};
  \draw     (Year.west) -- ++(left:3mm)
                        -- ([shift=(right:3mm)] 0,{(\Year-1995)/10})
                        --                     (0,{(\Year-1995)/10});
}
\end{scope}
\end{tikzpicture}
\end{document}

Output

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .