我正在使用 TikZ 包来创建堆叠时间轴。见下面的示例。每当我对时间轴进行一些小的修改时,我都必须花费大量时间调整所有坐标。如果有人能帮助我简化这一过程,我将不胜感激。我更具体的问题如下:
- 如何使 tikz 图像符合页面主体的尺寸?
- 如果时间线的尺寸发生变化,沿时间线放置的节点如何保持其相对间距?
- 时间线中引用的信息节点如何水平隔开以使其不相互重叠?(注意:我会考虑使用链或矩阵来做到这一点,但我不确定如何将时间线的其他元素与它们结合起来。)
代码:
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[american]{babel}
\usepackage{tikz}
\usetikzlibrary{snakes,positioning}
%% define help lines
\tikzset{help lines/.style={color=black!50,very thin}}
\tikzset{main labels/.style={
%Shape
rectangle,
% Size
minimum size=6mm,
rounded corners=2mm,
% Border
very thick,
draw=red!50!black!50,
%Filling
top color =white,
bottom color=red!50!black!20,
% Font
font=\sffamily,}}
\tikzset{side labels/.style={
%Shape
rectangle,
% Size
minimum size=6mm,
rounded corners=2mm,
% Border
very thick,
draw=black!50,
%Filling
top color =white,
bottom color=black!20,
% Font
font=\sffamily,
% Anchor
anchor=east,}}
\tikzset{date labels/.style={
% Font
font=\sffamily,
% Anchor
anchor=north east,
%Angle
rotate=45}}
\tikzset{event/.style={
%Shape
rectangle,
% Size
rounded corners=2mm,
% Border
thick,
draw=#1!50,
%Filling
fill = #1!20,
% Font
align=center,
font=\sffamily\scriptsize,
}}
\tikzset{outline/.default=black}
\begin{document}
\begin{tikzpicture} %
% draw help lines
\foreach \a in {1,2,6,7,11,12}
\draw [help lines](-1,\a) -- (10,\a);
% draw labels and titles
\node [main labels] at (5,13.5) {Community \#1};
\node [main labels] at (5,8.5) {Community \#2};
\node [main labels] at (5,3.5) {Community \#3};
\foreach \b in {2.5,7.5,12.5}
\node [side labels] at (-1,\b) {Response};
\foreach \c in {1.5,6.5,11.5}
\node [side labels] at (-1,\c) {Impact};
\foreach \d in {0.5,5.5,10.5}
\node [side labels] at (-1,\d) {Historical Event};
% draw dates
\draw [->] (0,9.9) -- (10,9.9);
\draw [->] (0,4.9) -- (.2, 4.9) {[snake] (.2, 4.9) -- (.8,4.9)} (.8,4.9) -- (1,4.9) -- (10,4.9);
\draw [->] (0,-0.9) -- (10,-0.9);
% draw date labels
\draw (0,4.85) node [date labels] {1690} -- (0,4.95) node (hua1690a) {};
\draw (1,4.85) node [date labels] {1970} -- (1,4.95) node (hua1970a) {};
\draw (3.076923,4.85) node [date labels] {1979} -- (3.076923,4.95) node (hua1979a) {};
% draw events
\begin{scope}[on grid]
\node (huafound) [event=blue] at (0,5.5) {\small Founded};
\draw [blue!50] (huafound) -- (hua1690a);
\node (huaroad) [event=blue] [right= 1.35 of huafound] {\small Road};
\draw [blue!50] (huaroad) -- (hua1970a);
\node (huaconasupo) [event=blue] at (3.076923,5.5) {\small CONASUPO};
\draw [blue!50] (huaconasupo) -- (hua1979a);
\end{scope}
\end{tikzpicture}
\end{document}
答案1
我的第一个想法是类似于下一个代码,但问题是 10/300 非常少,您也许可以修改一些值。
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[american]{babel}
\usepackage{tikz}
\tikzset{date labels/.style={
font=\small\sffamily,
anchor=north east,
rotate=45}}
\usetikzlibrary{snakes,positioning}
\begin{document}
\pgfmathsetmacro{\lentime}{0.9*\linewidth/28.45 pt}
\pgfmathsetmacro{\dateone}{0.9*\linewidth*(1.970-1.690)/(2.012-1.690)/28.45274 pt}
\pgfmathsetmacro{\datetwo}{0.9*\linewidth*(1.979-1.690)/(2.012-1.690)/28.45274 pt}
\begin{tikzpicture}
\draw [->] (0,0) -- (.2, 0) {[snake] (.2, 0) -- (\dateone,0)} (\dateone,0) -- (\lentime,0);
% draw date labels
\newcommand\ydelta{0.05}
\draw (0,0-\ydelta) node [date labels] {1690} -- (0,0+\ydelta) node (hua1690a) {};
\draw (\dateone,0-\ydelta) node [date labels] {1970} -- (\dateone,0+\ydelta) node (hua1970a) {};
\draw (\datetwo,0-\ydelta) node [date labels,anchor=south west] {1979} -- (\datetwo,0+\ydelta) node (hua1979a) {};
\end{tikzpicture}
\end{document}