基于这个问题,我想修改时间线右侧的框以显示标签(而不是年份),我想在每个条目的文本后立即指定该标签,也许在另一个 {...} 中。这可能吗?我见过链条手册,但这个似乎需要更多的知识。
\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}
还有第二条垂直线穿过文本,我还没想好要删除它,当我尝试将它包含在 documentclass[article] 中时,由于我不明白的原因,我得到了 1.5 页空白页,但这些都是次要问题。
答案1
第二条垂直线来自第一个循环的第二次迭代。链接的问答使用了值34
,我不知道为什么 OP 在他的原始代码中会用到这个值。只需删除 and 5
/或替换循环并替换0
为\xValue
(我在下面的代码中就是这么做的)。
你可以这样做
\node[base right=of Text] {\Label};
添加\Label
到循环变量后。
笔记:
1995.01
–1995.12
不会被视为多年来的线性发展。您需要进行一些调整才能允许实际日期。- 如果
\Label
是多线,它可能会高于\Year
节点,因此当链未调整时会产生不良结果。
代码
\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}