
tikzpicture で 2 つのタイムラインを作成しようとしています。上のタイムラインは希望どおりに見えますが、下のタイムラインでは問題が発生しています。小さな垂直の目盛りの代わりに、大きな対角線が生成されます。
\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);
}
そして2番目のセットは
\foreach \x in {0, 5, 10, 19, 30, 40}{
\draw (\x/2,-2.2) -- (\x/2,-1.8);
}
答え2
2 番目のケースでは、垂直線の y 座標の計算が間違っています。最初のケースでは、水平線の高さが であるため、計算は機能します0
。2 番目のケースでは、オフセット を追加する必要がありますが-2
、これは -library を使用して実現できますcalc
。
\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}