2

I'm trying to create two timelines with tikzpicture. The top one looks as I want, but I'm having troubles with the bottom one. Instead of having little vertical tick marks I'm generating big diagonals.

\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}

What am I doing wrong and how can I fix it?

Thanks!

1

I would explicitly define the coordinates of your vertical lines.

So your first vertical lines would become:

\foreach \x in {0, 5, 10, 19, 30, 40}{
   \draw (\x/2,-0.2) -- (\x/2,0.2);
}

and the second set would be

\foreach \x in {0, 5, 10, 19, 30, 40}{
   \draw (\x/2,-2.2) -- (\x/2,-1.8);
}

enter image description here

| improve this answer | |
  • Welcome to TeX.SX! It's better to provide full examples instead of fragments ;-) – user31729 Apr 17 '15 at 14:33
  • Thanks. But surely if you're only changing one or two lines of the original MWE, that's a lot of unnecessary text? – tmdavison Apr 17 '15 at 14:35
  • 1
    I think it's more about making it easier for the OP and others to use your answer: as it is now, you'd have to copy the MWE, then copy your fragment, and paste it in the appropriate place. If you include the corrected MWE you make everything easier. Besides, the beauty of minimal examples if that they will never be very big. :) – jja Apr 17 '15 at 14:39
2

The calculation of the y-coordinate for the vertical lines in the second case is wrong. In the first case it works, because the horizontal line is at height 0. In the second case you have to add the offset -2, which can be achieved with the 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}
| improve this answer | |
  • 1
    \draw[shift=(down:2)] (\x/2, 3pt) -- (\x/2, -3pt); should work as well and does not need the calc library. You also don't have to add the offset twice. Actually, it might be best to put the whole second part in a scope with the option shift=(down:2) (or 2cm for this kind of specification). – Qrrbrbirlbel Apr 17 '15 at 16:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.