在历史书中,您通常具有时间轴,其中事件和时间段以正确的彼此相对距离标记在一行上。在LaTeX中如何创建类似的东西?
Answers:
该tikz包似乎有你想要的东西。
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{snakes}
\begin{document}
\begin{tikzpicture}[snake=zigzag, line before snake = 5mm, line after snake = 5mm]
% draw horizontal line
\draw (0,0) -- (2,0);
\draw[snake] (2,0) -- (4,0);
\draw (4,0) -- (5,0);
\draw[snake] (5,0) -- (7,0);
% draw vertical lines
\foreach \x in {0,1,2,4,5,7}
\draw (\x cm,3pt) -- (\x cm,-3pt);
% draw nodes
\draw (0,0) node[below=3pt] {$ 0 $} node[above=3pt] {$ $};
\draw (1,0) node[below=3pt] {$ 1 $} node[above=3pt] {$ 10 $};
\draw (2,0) node[below=3pt] {$ 2 $} node[above=3pt] {$ 20 $};
\draw (3,0) node[below=3pt] {$ $} node[above=3pt] {$ $};
\draw (4,0) node[below=3pt] {$ 5 $} node[above=3pt] {$ 50 $};
\draw (5,0) node[below=3pt] {$ 6 $} node[above=3pt] {$ 60 $};
\draw (6,0) node[below=3pt] {$ $} node[above=3pt] {$ $};
\draw (7,0) node[below=3pt] {$ n $} node[above=3pt] {$ 10n $};
\end{tikzpicture}
\end{document}
我对tikz不太熟练,但这确实提供了一个很好的时间表,如下所示:
有一个新的chronology.sty由列维怀斯曼。该文档(pdf)说:
大多数用于LATEX的时间线包和解决方案都用于传达大量信息,因此是垂直设计的。如果您只是尝试为日期分配标签,则更传统的时间轴可能更合适。这就是年表的用途。
这是一些示例代码:
\documentclass{article}
\usepackage{chronology}
\begin{document}
\begin{chronology}[5]{1983}{2010}{3ex}[\textwidth]
\event{1984}{one}
\event[1985]{1986}{two}
\event{\decimaldate{25}{12}{2001}}{three}
\end{chronology}
\end{document}
产生以下输出:
\textwidth
?
{3ex}
)。
只是一个更新。
当前的TiKZ软件包将发出:软件包tikz警告:蛇已被装饰品取代。请在输入行上使用装饰库而不是蛇库。。。
因此,代码的相关部分必须更改为:
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{decorations}
\begin{document}
\begin{tikzpicture}
%draw horizontal line
\draw (0,0) -- (2,0);
\draw[decorate,decoration={snake,pre length=5mm, post length=5mm}] (2,0) -- (4,0);
\draw (4,0) -- (5,0);
\draw[decorate,decoration={snake,pre length=5mm, post length=5mm}] (5,0) -- (7,0);
%draw vertical lines
\foreach \x in {0,1,2,4,5,7}
\draw (\x cm,3pt) -- (\x cm,-3pt);
%draw nodes
\draw (0,0) node[below=3pt] {$ 0 $} node[above=3pt] {$ $};
\draw (1,0) node[below=3pt] {$ 1 $} node[above=3pt] {$ 10 $};
\draw (2,0) node[below=3pt] {$ 2 $} node[above=3pt] {$ 20 $};
\draw (3,0) node[below=3pt] {$ $} node[above=3pt] {$ $};
\draw (4,0) node[below=3pt] {$ 5 $} node[above=3pt] {$ 50 $};
\draw (5,0) node[below=3pt] {$ 6 $} node[above=3pt] {$ 60 $};
\draw (6,0) node[below=3pt] {$ $} node[above=3pt] {$ $};
\draw (7,0) node[below=3pt] {$ n $} node[above=3pt] {$ 10n $};
\end{tikzpicture}
\end{document}
高温超导
\usetikzlibrary{decorations.pathmorphing}
。另外,\documentclass[tikz]{standalone}
如果要裁剪的图片插入另一个文档,请执行此操作。
蒂姆·斯托尔(Tim Storer)编写了一个更灵活,更漂亮的外观timeline.sty
(Internet存档回溯机链接,原来的链接不见了)。另外,该线是水平的而不是垂直的。因此,例如:
\begin{timeline}{2008}{2010}{50}{250}
\MonthAndYearEvent{4}{2008}{First Podcast}
\MonthAndYearEvent{7}{2008}{Private Beta}
\MonthAndYearEvent{9}{2008}{Public Beta}
\YearEvent{2009}{IPO?}
\end{timeline}
产生如下所示的时间轴:
2008 2010
· · April, 2008 First Podcast ·
· July, 2008 Private Beta
· September, 2008 Public Beta
· 2009 IPO?
就个人而言,我发现这是一个比其他答案更令人愉悦的解决方案。但是我也发现自己正在修改代码,以使其更接近我认为的时间表。因此,我认为没有确定的解决方案。
首先,我更喜欢tikz
引导式解决方案,因为它给您更多的自由。其次,我没有发布任何全新的内容。这显然与佐伊·加格农的答案相似,因为他指明了道路。
我需要一些时间安排,花了一些时间(真是令人惊讶!),所以我分享了结果。我希望你会喜欢。
\documentclass[tikz]{standalone}
\usepackage{verbatim}
\begin{document}
\newlength\yearposx
\begin{tikzpicture}[scale=0.57] % timeline 1990-2010->
% define coordinates (begin, used, end, arrow)
\foreach \x in {1990,1992,2000,2002,2004,2005,2008,2009,2010,2011}{
\pgfmathsetlength\yearposx{(\x-1990)*1cm};
\coordinate (y\x) at (\yearposx,0);
\coordinate (y\x t) at (\yearposx,+3pt);
\coordinate (y\x b) at (\yearposx,-3pt);
}
% draw horizontal line with arrow
\draw [->] (y1990) -- (y2011);
% draw ticks
\foreach \x in {1992,2000,2002,2004,2005,2008,2009}
\draw (y\x t) -- (y\x b);
% annotate
\foreach \x in {1992,2002,2005,2009}
\node at (y\x) [below=3pt] {\x};
\foreach \x in {2000,2004,2008}
\node at (y\x) [above=3pt] {\x};
\begin{comment}
% for use in beamer class
\only<2> {\fill (y1992) circle (5pt);}
\only<3-5> {\fill (y2000) circle (5pt);}
\only<4-5> {\fill (y2002) circle (5pt);}
\only<5> {\fill[red] (y2004) circle (5pt);}
\only<6> {\fill (y2005) circle (5pt);}
\only<7> {\fill[red] (y2005) circle (5pt);}
\only<8-11> {\fill (y2008) circle (5pt);}
\only<11> {\fill (y2009) circle (5pt);}
\end{comment}
\end{tikzpicture}
\end{document}
如您所见,它是针对投影仪演示(选择零件以及缩放选项)而量身定制的,但是,如果您真的想在演示中进行测试,则应该移出\newlength\yearposx
框架定义,因为否则会出现错误提示该命令\yearposx
已经定义(除非您从框架中删除选择部件和任何其他框架拆分命令)。
有timeline.sty浮动。
语法比使用tikz更简单:
%%% In LaTeX:
%%% \begin{timeline}{length}(start,stop)
%%% .
%%% .
%%% .
%%% \end{timeline}
%%%
%%% in plain TeX
%%% \timeline{length}(start,stop)
%%% .
%%% .
%%% .
%%% \endtimeline
%%% in between the two, we may have:
%%% \item{date}{description}
%%% \item[sortkey]{date}{description}
%%% \optrule
%%%
%%% the options to timeline are:
%%% length The amount of vertical space that the timeline should
%%% use.
%%% (start,stop) indicate the range of the timeline. All dates or
%%% sortkeys should lie in the range [start,stop]
%%%
%%% \item without the sort key expects date to be a number (such as a
%%% year).
%%% \item with the sort key expects the sort key to be a number; date
%%% can be anything. This can be used for log scale time lines
%%% or dates that include months or days.
%%% putting \optrule inside of the timeline environment will cause a
%%% vertical rule to be drawn down the center of the timeline.
我已经使用python的datetime.data.toordinal在包的上下文中将日期转换为“排序键”。