[Tex/LaTex] Typesetting public transport timetables

packages

I know that Deutsche Bahn (German railway) is using (La)TeX to typeset their timetables. Are there any (freely available) packages that help in typesetting timetables? I'd be mostly interested in connection timetables, i.e. something like:

  • take train 123 at 5:45 from SomeStation platform 1 in direction of SomeFarAwayStation

  • [105 min]

  • arrive at ChangeStation platform 3 at 7:30

  • walk for 150 m to the bus stop SomeBusStop [3 min]
  • take bus 987 at 7:38 in direction of SomeFarAwayBusStop
  • ….

All of this of course should be prettily formatted, perhaps even with some icons (for "bus/train/…").

One layout that I like is the one of VGN: timetable

enter image description here

Best Answer

Here's a stab. I've edited to create the environment timetable, which sets up the TABstack, and lets you fill in the details. I've added a variety of helper macros for regular things, like

  1. \firststation, \nextstation, and \laststation for the symbols in the first column;

  2. \terminus{} and \waypoint{} for the names of the endpoint and waypoint stations;

  3. \routedetails[<direction modifier>]{<mode>}{<number>}{<direction>} for the route data;

  4. \onbus, \onmetro, and \ontrain to provide icons for the various transportation modes; and

  5. \depart{}, \arrive{}, and \duration{} for the timing.

EDITED to use appropriate clipart

https://www.iconsdb.com/red-icons/bus-icon.html

http://www.clker.com/clipart-subway-blue.html

http://www.softicons.com/web-icons/awt-travel-blue-icons-by-awt-media/train-icon

(Make sure you use the latest version of tabstackengine 2018/03/05 (V2.10))

The following MWE compiles as is, but if you download the cited icons, you can also uncomment the redefinitions to get those icons, as I show in the actual image.

\documentclass{article}
\usepackage[TABcline]{tabstackengine}
\usepackage{xcolor,graphicx,amssymb,environ}
\newcommand\onbus{\includegraphics[width=2ex,height=2ex]{example-image-a}}% BUS
\newcommand\onmetro{\includegraphics[width=2ex,height=2ex]{example-image-b}}% METRO
\newcommand\ontrain{\includegraphics[width=2ex,height=2ex]{example-image-c}}% TRAIN
% UNCOMMENT THE REDEFINITIONS BELOW IF YOU DOWNLOADED THE ICONS
%% https://www.iconsdb.com/red-icons/bus-icon.html
%\renewcommand\onbus{\includegraphics[width=2ex,height=2ex]{bus-xxl}}
%% http://www.clker.com/clipart-subway-blue.html
%\renewcommand\onmetro{\includegraphics[width=2ex,height=2ex]{subway-blue-md}}
%% http://www.softicons.com/web-icons/awt-travel-blue-icons-by-awt-media/train-icon
%\renewcommand\ontrain{\includegraphics[width=2ex,height=2ex]{AWT-Train}}
%%%%
% THE pt DISTANCES ON NEXT LINE MAY NEED TO VARY WITH FONT AND FONTSIZE
\newcommand\Stellemark[2]{\smash{\stackon[5.5pt]{\stackunder[-.5pt]{$\square$}{%
  \textcolor{blue!70!black}{\rule[-#2]{2\fboxrule}{#2}}}}{%
  \textcolor{blue!70!black}{\rule{2\fboxrule}{#1}}}}\kern-5pt}
\newcommand\terminus[1]{\smash{\textcolor{green!50!black}{\textbf{#1}}}}
% THE \raisebox VALUE ON THE NEXT TWO LINES MAY NEED TO VARY WITH FONT AND FONTSIZE
\newcommand\waypoint[1]{\smash{\raisebox{-4pt}{\terminus{#1}}}\rlap{\hspace{1em}\TABrule}}
\newcommand\nextstation{\smash{\raisebox{-4.4pt}{\Stellemark{14pt}{14pt}}}}
\newcommand\firststation{\Stellemark{0pt}{14pt}}
\newcommand\laststation{\Stellemark{14pt}{0pt}}
\newcommand\duration[1]{\stackunder{}{#1 min.}}
\newcommand\routedetails[4][Richtung:\ ]{#2\ \stackunder{\textbf{#3}}{#1#4}}
\newcommand\depart[1]{ab #1}
\newcommand\arrive[1]{an #1}
\let\svTABrule\TABrule
\NewEnviron{timetable}[1]{%
  \noindent%
  \footnotesize%
  \sffamily%
  \setstackgap{S}{1pt}%
  \renewcommand\stacktype{L}%
  \setstacktabulargap{1em}%
  \def\TABruleshift{-2pt}%
  \fboxrule=1pt\relax%
  \renewcommand\TABrule{\textcolor{green!50!black}{\svTABrule}}%
  \def\tmp{\tabularShortstack{#1}}%
  \expandafter\tmp\expandafter{\BODY}%
}
\begin{document}
\begin{timetable}{cclcclr}
 && \textbf{Haltestelle} & \textbf{Uhrzeit} & \textbf{Gleis} & 
 \textbf{Verkehrsmittel} & \textbf{Dauer}\\
%
 \TABcline{1-7}
%
 \firststation && \terminus{N\"urnberg Flughafen}& \depart{10:22}&& 
 \routedetails{\onmetro}{U2}{R\"othenbach}& \duration{7}\\
%
 &&&\arrive{10:29}&&&\\
%
 \nextstation&\TABrule&\waypoint{N\"urnberg Mooshof}&
 \TABrule&\TABrule&\TABrule&\TABrule\\ 
%
 &&&\depart{10:35} &7& \routedetails{\ontrain}{65}{R\"othenbach} & \duration{6}\\
%
 &&&\arrive{10:41}&12&&\\
%
 \nextstation&\TABrule&\waypoint{N\"urnberg Schoppershof}&
 \TABrule&\TABrule&\TABrule&\TABrule\\ 
%
 &&&\depart{10:45}&&\routedetails[Nur: ]{\onbus}{73}{Dutzendteich}&\duration{11}\\
%
 \laststation && \terminus{N\"urnberg-Dutzendteich} & \arrive{10:56}&&&\\
%
 \TABcline{1-7}
\end{timetable}
\end{document}

enter image description here