
Estoy intentando crear dos líneas de tiempo con tikzpicture. El de arriba se ve como quiero, pero tengo problemas con el de abajo. En lugar de tener pequeñas marcas verticales, estoy generando grandes diagonales.
\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}
¿Qué estoy haciendo mal y cómo puedo solucionarlo?
¡Gracias!
Respuesta1
Definiría explícitamente las coordenadas de sus líneas verticales.
Entonces tus primeras líneas verticales se convertirían en:
\foreach \x in {0, 5, 10, 19, 30, 40}{
\draw (\x/2,-0.2) -- (\x/2,0.2);
}
y el segundo set seria
\foreach \x in {0, 5, 10, 19, 30, 40}{
\draw (\x/2,-2.2) -- (\x/2,-1.8);
}
Respuesta2
El cálculo de la coordenada y para las líneas verticales en el segundo caso es incorrecto. En el primer caso funciona, porque la línea horizontal está en altura 0
. En el segundo caso hay que agregar el offset -2
, lo que se puede lograr con 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}