答案1
如果你无法避免在线的两边都贴标签,我建议将年份标签放在线上。中心而不是放在一边。以下是不太复杂的格式:
显然,可以根据偏好、受众和内容使整体外观更加美观。但是,以下kronos
样式提供了基本结构,并根据可以修改的各种变量的值(start
、end
、step
和)确定标签和事件的位置。然后可以使用将事件放在线上。带星号的版本将它们放在右侧;无星号的版本放在左侧。第一个可选参数可用于设置除默认值以外的其他值(除非所有事件都同时发生,height
否则可能是必需的,在这种情况下时间轴没什么用),强制参数指定事件的描述。width
\kronosevent*[]{}
year
例如,上面的内容是使用tikzpicture
环境的可选参数指定的。这将使用、、和 的默认kronos
值设置时间线。start
end
step
width
height
然后,图片指定了 3 个事件 - 左侧 2 个,右侧 1 个。第一个
\kronosevent{Something here}
使用默认设置,将事件置于线左侧 1850 处。第二个
\kronosevent[year=300]{Something\\with a long\\description\\happened\\a while ago}
将指定时间(公元 300 年)的事件放在行的左侧,而第三个
\kronosevent*[year=1457]{Major changes}
将公元 1457 年发生的事件置于该线的右侧。
完整代码:
\documentclass[tikz,multi,border=10pt]{standalone}
\usepackage{xparse}
\usetikzlibrary{arrows.meta}
\pgfkeys{/pgf/number format,
int detect,
set thousands separator={},
}
\tikzset{
kronos/.code={% http://tex.stackexchange.com/a/159856/ - Claudio Fiandrino
\tikzset{%
align=center,
anchor=mid,
/kronos/.cd,
#1
}%
\pgfmathsetmacro\kronosunit{(\kronosheight-20pt)/(\kronosend-\kronosstart)}%
\draw [line width=1pt] (-.5*\kronoswidth,10pt) coordinate (kronos tl) ++(3.5pt,0) coordinate (kronos pre) -- ++(0,-\kronosheight) ++(\kronoswidth-3.5pt,0) coordinate (kronos br) ++(-3.5pt,0) coordinate (kronos post) -- (kronos post |- kronos pre);
\coordinate (kronos start) at (0,0);
\coordinate (kronos end) at ([yshift=10pt]kronos post);
\pgfmathsetmacro\tempa{int(\kronosstart+\kronosstep)}%
\foreach \i in {\kronosstart,\tempa,...,\kronosend} {%
\node (\i) [font=\sffamily] at (0,{(\kronosstart-\i)*\kronosunit pt}) {\i};
\draw [thick] (\i.west -| kronos pre) -- +(-3.5pt,0) (\i.east -| kronos post) -- +(3.5pt,0);
}
},
kronos arrow/.style={{Stealth[]}-, thick, shorten <=2.5pt},
kronos event/.search also={/kronos,/tikz},
kronos event/year/.store in=\kronosyear,
kronos event/year=1850,
/kronos/.search also={/tikz},
/kronos/.cd,
start/.store in=\kronosstart,
end/.store in=\kronosend,
step/.store in=\kronosstep,
width/.store in=\kronoswidth,
height/.store in=\kronosheight,
start=200,
end=2000,
width=10mm,
height=100mm,
step=200,
}
\NewDocumentCommand\kronosevent { s O {} m }
{%
\tikzset{%
kronos event/.cd,
#2
}
\coordinate (a) at (0,{(\kronosstart-\kronosyear)*\kronosunit pt});
\IfBooleanTF {#1}
{%
\draw [kronos arrow] (a -| kronos br) -- ++(30pt,0) node [anchor=west, align=left, font=\footnotesize\sffamily] {\textbf{\kronosyear} #3};
}{%
\draw [kronos arrow] (a -| kronos tl) -- ++(-30pt,0) node [anchor=east, align=left, font=\footnotesize\sffamily] {\textbf{\kronosyear} #3};
}
}
\begin{document}
\begin{tikzpicture}
[kronos]
\kronosevent{Something here}
\kronosevent[year=300]{Something\\with a long\\description\\happened\\a while ago}
\kronosevent*[year=1457]{Major changes}
\end{tikzpicture}
\end{document}