# vertical timelines that overlap outer margin

I'm using LaTeX and memoir. I wish to have timelines in which the year extends into the outer margin. I would just make these hard-coded bitmap figures, except I don't want to have to redraw them (swapping left/right of timeline) every time a pagination change moves a timeline from a recto page to a verso or vice versa. Here's a sketch of what I'm shooting for (left-hand page):

If this can be done with canned packages, that's great. If not, pointers on how to go about coding it without getting too far over my head too fast would be much appreciated. If it's too crazy, I guess my fallback scheme would be to make two hard-coded (left/right) bitmaps of each timeline and try to make code to insert (using insbox or something) the correct one for the current page.

This is just a proof of concept. Some things are hard coded, but since you do not provide very much information on the details, I do not know what will vary and what won't.

\documentclass[twoside]{article}
\usepackage{wrapfig}
\usepackage{eso-pic}
\usepackage{tikzpagenodes}
\usepackage{lipsum}
\newcounter{timeline}
\newcommand{\TimeLine}[2][10]{\stepcounter{timeline}
\begin{wrapfigure}[#1]{o}[10pt]{4cm}
\begin{tikzpicture}[remember picture]
\path (0,0) coordinate (TL-\thetimeline-bottom);
\path (0,{(#1-2)*12pt}) coordinate (TL-\thetimeline-top);
\end{tikzpicture}
\end{wrapfigure}
\ifodd\thepage
\begin{tikzpicture}[remember picture,overlay,font=\sffamily]
\foreach [count=\Z] \X/\Y  in {#2}
{
\xdef\Nmax{\Z}
}
\draw[very thick,-latex] (current page text area.east |- TL-\thetimeline-bottom) --
(current page text area.east |- TL-\thetimeline-top)
foreach [count=\Z] \X/\Y  in {#2} {coordinate[{pos=\Z/(\Nmax+1)}]
(TL-\thetimeline-\Z) };
\foreach [count=\Z] \X/\Y  in {#2}
{
\draw ([xshift=-1mm]TL-\thetimeline-\Z)
node[left]{\Y} -- ([xshift=+1mm]TL-\thetimeline-\Z) node[right]{\X};
}
\end{tikzpicture}
\else
\begin{tikzpicture}[remember picture,overlay,font=\sffamily]
\foreach [count=\Z] \X/\Y  in {#2}
{
\xdef\Nmax{\Z}
}
\draw[very thick,-latex] (current page text area.west |- TL-\thetimeline-bottom) --
(current page text area.west |- TL-\thetimeline-top)
foreach [count=\Z] \X/\Y  in {#2} {coordinate[{pos=\Z/(\Nmax+1)}]
(TL-\thetimeline-\Z) };
\foreach [count=\Z] \X/\Y  in {#2}
{
\draw ([xshift=-1mm]TL-\thetimeline-\Z)
node[left]{\X} -- ([xshift=+1mm]TL-\thetimeline-\Z) node[right]{\Y};
}
\end{tikzpicture}
\fi
}}
\begin{document}
\lipsum[1-3]
\TimeLine{1998/France,2002/Brazil,2006/Italy}
\lipsum[4-6]
\TimeLine{2010/Spain,2014/Germany,2018/France}
\lipsum[7-9]
\end{document}


As you can see, the times/dates are always outside.

• Thanks -- that's exactly the look I wanted! I'm studying this to see if I can understand all the pieces. I had the impression wrapfig was pretty fragile, but I'm happy to try it and see how it works out. – Ron Burk Sep 25 '18 at 21:46
• @RonBurk It might well be that wrapfig has weaknesses (even though I used it in many documents for more than a decade and never had real problems, but there might be conflicts with document classes I am not using, so I dunno). Notice, however, that wrapfig is not at all essential to this answer. If you have another way of doing something similar to wrapfig, I'll be happy to try rewriting my answer using this. The key point is that (1) I create some empty space and (2) fill it with some overlay at the time of shipout when the page number is known. – user121799 Sep 25 '18 at 22:40