我对时间表有一些疑问:
- 我想让时间线适合文本宽度并且还想居中。
- 我们怎样才能跳到下一行?
如果同一日期(例如 1941 年)包含三行或四行,则文本会交织在一起。也许我们可以跳到下一行。(或者也许增加行间距是另一种解决方案,但是当行间距太大时,看起来就不好看。)
``
\usepackage{environ}
\usepackage{tikz}
\usetikzlibrary{calc,matrix}
%Code by Claudio:
%https://tex.stackexchange.com/a/197447/221452
% Uses code by Andrew:
%% http://tex.stackexchange.com/a/28452/13304
\makeatletter
\let\matamp=&
\catcode`\&=13
\def&{%
\iftikz@is@matrix%
\pgfmatrixnextcell%
\else%
\matamp%
\fi%
}
\makeatother
\newcounter{lines}
\def\endlr{\stepcounter{lines}\\}
\newcounter{vtml}
\setcounter{vtml}{0}
\newif\ifvtimelinetitle
\newif\ifvtimebottomline
\tikzset{
description/.style={column 2/.append style={#1}},
timeline color/.store in=\vtmlcolor,
timeline color=red!80!black,
timeline color st/.style={fill=\vtmlcolor,draw=\vtmlcolor},
use timeline header/.is if=vtimelinetitle,
use timeline header=false,
add bottom line/.is if=vtimebottomline,
add bottom line=false,
timeline title/.store in=\vtimelinetitle,
timeline title={},
line offset/.store in=\lineoffset,
line offset=4pt,
}
\NewEnviron{vtimeline}[1][]{%
\setcounter{lines}{1}%
\stepcounter{vtml}%
\begin{tikzpicture}[column 1/.style={anchor=east},
column 2/.style={anchor=west},
text depth=0pt,text height=1ex,
row sep=1ex,
column sep=1em,
#1
]
\matrix(vtimeline\thevtml)[matrix of nodes]{\BODY};
\pgfmathtruncatemacro\endmtx{\thelines-1}
\path[timeline color st]
($(vtimeline\thevtml-1-1.north east)!0.5!(vtimeline\thevtml-1-2.north west)$)--
($(vtimeline\thevtml-\endmtx-1.south east)!0.5!(vtimeline\thevtml-\endmtx-2.south west)$);
\foreach \x in {1,...,\endmtx}{
\node[circle,timeline color st, inner sep=0.15pt, draw=white, thick]
(vtimeline\thevtml-c-\x) at
($(vtimeline\thevtml-\x-1.east)!0.5!(vtimeline\thevtml-\x-2.west)$){};
\draw[timeline color st](vtimeline\thevtml-c-\x.west)--++(-3pt,0);
}
\ifvtimelinetitle%
\draw[timeline color st]([yshift=\lineoffset]vtimeline\thevtml.north west)--
([yshift=\lineoffset]vtimeline\thevtml.north east);
\node[anchor=west,yshift=16pt,font=\large]
at (vtimeline\thevtml-1-1.north west)
{\textsc{Timeline \thevtml}: \textit{\vtimelinetitle}};
\else%
\relax%
\fi%
\ifvtimebottomline%
\draw[timeline color st]([yshift=-\lineoffset]vtimeline\thevtml.south west)--
([yshift=-\lineoffset]vtimeline\thevtml.south east);
\else%
\relax%
\fi%
\end{tikzpicture}
}
\begin{document}
\begin{center}
\begin{vtimeline}[description={text width=\textwidth},
row sep=4ex,
use timeline header,
timeline title={The timeline of the Lorem Ipsum}]
1921 & Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. \endlr
1941 & It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. \endlr
1991 & Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old.Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old.
\end{vtimeline}
\end{center}
\end{document}
``