我正在尝试使用 tikzpicture 创建两个时间轴。上面的时间轴看起来符合我的要求,但下面的时间轴却出现了问题。我没有生成小的垂直刻度标记,而是生成了大对角线。
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{tikz}
\usetikzlibrary{snakes}
\usepackage{fullpage}
\usepackage{graphicx}
\begin{document}
\resizebox{\linewidth}{!}{% Resize table to fit within
\begin{tikzpicture}[snake=zigzag, line before snake = 5mm, line after snake = 5mm]
%draw horizontal line
\draw (0,0) -- (19/2,0);
\draw[snake] (19/2,0) -- (25/2,0);
\draw (25/2,0) -- (30/2,0);
\draw[snake] (30/2,0) -- (35/2,0);
\draw (35/2,0) -- (40/2,0);
%draw vertical lines
\foreach \x in {0, 5, 10, 19, 30, 40}{
\draw (\x/2,3pt) -- (\x/2,-3pt);
}
%draw nodes
\draw (-2,0) node { PHYS1060 };
\draw (0,0) node[below=3pt] { Pre-test published } node[above=3pt] { Jan 4, 2014 };
\draw (5/2,0) node[below=3pt] { Nudge } node[above=3pt] { Jan 9, 2014 };
\draw (10/2,0) node[below=3pt] { First class } node[above=3pt] { Jan 13, 2014 };
\draw (19/2,0) node[below=3pt] { Pre-test due } node[above=3pt] { Jan 22, 2014 };
\draw (30/2,0) node[below=3pt] { Midterm } node[above=3pt] { Feb 17, 2014 };
\draw (40/2,0) node[below=3pt] { Final Exam} node[above=3pt] { May 5, 2014 };
%draw horizontal line
\draw (-2,-2) node { PHYS1050 };
\draw (0,-2) -- (19/2,-2);
\draw[snake] (19/2,-2) -- (25/2,-2);
\draw (25/2,-2) -- (30/2,-2);
\draw[snake] (30/2,-2) -- (35/2,-2);
\draw (35/2,-2) -- (40/2,-2);
draw vertical lines
\foreach \x in {0, 5, 10, 19, 30, 40}{
\draw (\x/2,-2,3pt) -- (\x/2,-2,-3pt);
}
%draw nodes
\draw (0,-2) node[below=3pt] { Pre-test published } node[above=3pt] { Aug 10, 2014 };
\draw (5/2,-2) node[below=3pt] { First class } node[above=3pt] { Aug 27, 2014 };
\draw (10/2,-2) node[below=3pt] { Nudge } node[above=3pt] { Sept 4, 2014 };
\draw (19/2,-2) node[below=3pt] { Pre-test due } node[above=3pt] { Sept 7, 2014 };
\draw (30/2,-2) node[below=3pt] { Midterm } node[above=3pt] { ?, 2014 };
\draw (40/2,-2) node[below=3pt] { Final Exam} node[above=3pt] { ?, 2014 };
\end{tikzpicture}
}
\end{document}
我做错了什么?我该如何解决?
谢谢!
答案1
我会明确定义你的垂直线的坐标。
因此你的第一条垂直线将变成:
\foreach \x in {0, 5, 10, 19, 30, 40}{
\draw (\x/2,-0.2) -- (\x/2,0.2);
}
第二组是
\foreach \x in {0, 5, 10, 19, 30, 40}{
\draw (\x/2,-2.2) -- (\x/2,-1.8);
}
答案2
第二种情况下垂直线的 y 坐标计算错误。第一种情况下计算正确,因为水平线的高度为0
。第二种情况下必须添加偏移量-2
,这可以通过calc
-library 实现。
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{tikz}
\usetikzlibrary{snakes}
\usepackage{fullpage}
\usepackage{graphicx}
\usetikzlibrary{calc}
\begin{document}
\resizebox{\linewidth}{!}{% Resize table to fit within
\begin{tikzpicture}[snake=zigzag, line before snake = 5mm, line after snake = 5mm]
%draw horizontal line
\draw (0,0) -- (19/2,0);
\draw[snake] (19/2,0) -- (25/2,0);
\draw (25/2,0) -- (30/2,0);
\draw[snake] (30/2,0) -- (35/2,0);
\draw (35/2,0) -- (40/2,0);
%draw vertical lines
\foreach \x in {0, 5, 10, 19, 30, 40}{
\draw (\x/2,3pt) -- (\x/2,-3pt);
}
%draw nodes
\draw (-2,0) node { PHYS1060 };
\draw (0,0) node[below=3pt] { Pre-test published } node[above=3pt] { Jan 4, 2014 };
\draw (5/2,0) node[below=3pt] { Nudge } node[above=3pt] { Jan 9, 2014 };
\draw (10/2,0) node[below=3pt] { First class } node[above=3pt] { Jan 13, 2014 };
\draw (19/2,0) node[below=3pt] { Pre-test due } node[above=3pt] { Jan 22, 2014 };
\draw (30/2,0) node[below=3pt] { Midterm } node[above=3pt] { Feb 17, 2014 };
\draw (40/2,0) node[below=3pt] { Final Exam} node[above=3pt] { May 5, 2014 };
%draw horizontal line
\draw (-2,-2) node { PHYS1050 };
\draw (0,-2) -- (19/2,-2);
\draw[snake] (19/2,-2) -- (25/2,-2);
\draw (25/2,-2) -- (30/2,-2);
\draw[snake] (30/2,-2) -- (35/2,-2);
\draw (35/2,-2) -- (40/2,-2);
draw vertical lines
\foreach \x in {0, 5, 10, 19, 30, 40}{
\draw ($(0,-2)+(\x/2, 3pt)$) -- ($(0,-2)+(\x/2, -3pt)$);
}
%draw nodes
\draw (0,-2) node[below=3pt] { Pre-test published } node[above=3pt] { Aug 10, 2014 };
\draw (5/2,-2) node[below=3pt] { First class } node[above=3pt] { Aug 27, 2014 };
\draw (10/2,-2) node[below=3pt] { Nudge } node[above=3pt] { Sept 4, 2014 };
\draw (19/2,-2) node[below=3pt] { Pre-test due } node[above=3pt] { Sept 7, 2014 };
\draw (30/2,-2) node[below=3pt] { Midterm } node[above=3pt] { ?, 2014 };
\draw (40/2,-2) node[below=3pt] { Final Exam} node[above=3pt] { ?, 2014 };
\end{tikzpicture}
}
\end{document}