10

As there are so many fancy things which can be done with LaTeX, is there a possibility to create layouts for model railroads? I know only dedicated (mostly Windows) programs, to do that, e.g. http://www.sandiasoftware.com/ (the following picture is from that site)

enter image description here

I think, with TikZ this should be possible (for 2D).

TobiBS
  • 5,240
Micha
  • 2,869
  • 5
    Can you give a few examples of model railway layouts? – percusse May 01 '13 at 22:35
  • 9
    As always, anything is possible. To be honest, I would do this in a vector drawing software like Inkscape and create 'brushes' for buildings and trees and other standard items. Then you can draw the tracks as pathes and 'stamp in' the rest. I think it takes a very long time to create a, say, tikz object database to be productive. But it is possible if you re willing to write 5000 lines code :) – Martin H May 01 '13 at 23:04
  • Go 3D, and use some of the tools discussed in Draw an aircraft with Tikz. – Werner Aug 16 '13 at 23:31
  • Is there anyone still interested in this question? I started to write some tikz code to plan the layout of my old Märklin tracks. It can be easily changed to tracks of other manufacturers. Finally, there will be a configuration section to change this. I am quite satisfied so far with the tikz solution. For a planar layout I am 30% done with the implementation. When it is finished, I will make it available to anyone. Until then, I will be happy to share it with people who are interested and who want to discuss the syntax with me. – pddp Apr 01 '19 at 10:46

2 Answers2

11

There are several programs to plan and construct a model railway. And it seems you know at last one of them. One advantage of them is that they can print a list of used parts to build the model railway.

To create the layouted plan with TikZ you have to write a new code to layout the plan with TikZ. That is not easy and a lot of work (as also @MartinH said in his comment).

I personaly think it makes no sense to recreate that. Better is to use the existing program and include the result with \includegraphics. If you have problems with the quality of the picture change the format in the planing software for saving the plan (to .jpg, .pdf, .epc). If that is not possible consider to change the planing program for the model railway.

Mensch
  • 65,388
  • 2
    Even if the specialized software is expensive, I have to agree that a system this complex and specialized (and inherently layout-oriented) is best done with graphical editors. Everything else is just impractical and, honestly, a waste of time. (Unless it's a hobby, of course!) – Sean Allred Aug 14 '13 at 04:15
1

I came across this question recently and remembered, that I had already done something like it. Therefore I would like to share my approach with you. The general idea is to define the underlying drawing mechanism and a style. Then you need to define the spcific tracks for a certain manufacturer (in my case Märklin) and then you can start drawing.

While it is really simple to draw straight and curve segments, it gets tricky with switches. As my solution is just a proof of concept, I applied a technique where the switch can only be inserted from the single ended side and you continue to draw from the straight end. The curved end location is stored and you need to start a new trunk from there. In stations this can be quite tricky and it would be useful to create a mechanism to define with which side you want to start. Also the definition of switches is not automated yet, like the straights and curves are. Nevertheless it shows it is possible, but requires a special way of thinking right now.

What is of course also possible is, that you place locomotives, waggons, houses and everything else on or beside the tracks. Just load an image and scale it correctly and you are done. That way it is easy to determine if the length of a track is enough and so on.

So here is my result and the code is below:

enter image description here

\documentclass[tikz,border=5mm]{standalone}

\usepackage[sfdefault,lining]{FiraSans} \usepackage{siunitx}

\usetikzlibrary{decorations.markings,decorations.pathmorphing,decorations.pathreplacing,arrows.meta}

%Redefine font size \renewcommand{\scriptsize}{\fontsize{1.5mm}{2mm}\selectfont}

%Starting angle \newcommand{\currentangle}{180}

%Save and restore a position and an angle (for switches) \newcommand{\storeLocation}[2]{coordinate(#1) \pgfextra{\pgfmathsetmacro\switchangle{\currentangle + #2} \expandafter\xdef\csname #1\endcsname{\switchangle}}} \newcommand{\getLocation}[1]{\pgfextra{\renewcommand{\currentangle}{\csname #1\endcsname}} (#1)} \newcommand{\getLocationInverted}[1]{\pgfextra{\renewcommand{\currentangle}{\csname #1\endcsname}\pgfmathsetmacro\currentangle{\currentangle + 180}} (#1)}

%Commands to create new track \newcommand{\newTrack}[3][]{\renewcommand{\currentangle}{#2}\draw[line width=4,postaction=show track segments,#1] #3;}

%Commands to create new curved track \newcommand{\curveL}[3]{arc (\currentangle-180:\currentangle - 180 + #2:#3) node[midway,sloped,white,font=\scriptsize]{#1} \pgfextra{\pgfmathsetmacro\currentangle{\currentangle + #2}}} \newcommand{\curveR}[3]{arc (\currentangle:\currentangle - #2:#3) node[midway,sloped,white,font=\scriptsize]{#1} \pgfextra{\pgfmathsetmacro\currentangle{\currentangle - #2}}} \newcommand{\newcurve}[4]{\expandafter\newcommand\csname #1L\endcsname{\curveL{#2}{#3}{#4}}\expandafter\newcommand\csname #1R\endcsname{\curveR{#2}{#3}{#4}}}

%Define curves for Märklin \newcurve{s}{24130}{30}{36} \newcurve{m}{24230}{30}{43.75} \newcurve{l}{24330}{30}{51.5} \newcurve{xl}{24430}{30}{57.93} \newcurve{xxl}{24530}{30}{64.36} \newcurve{wide}{24912}{12.1}{111.46}

%Commands to create new straight track \newcommand{\newstraight}[3]{\expandafter\newcommand\csname #1\endcsname{-- ++(\currentangle - 90:#3) node[midway,sloped,white,font=\scriptsize]{#2}}}

%Define straights for Märklin \newstraight{single}{24180}{18} \newstraight{double}{24360}{36}

%Define switches \newcommand{\wideSwitchL}[1]{coordinate(switchstart) arc (\currentangle-180:\currentangle - 180 + 12.1:111.46) \storeLocation{#1}{+12.1} (switchstart) -- ++(\currentangle-90:23.61) node[midway,sloped,white,font=\scriptsize]{24711}}

\newcommand{\wideSwitchR}[1]{coordinate(switchstart) arc (\currentangle:\currentangle - 12.1:111.46) \storeLocation{#1}{-12.1} (switchstart) -- ++(\currentangle-90:23.61) node[midway,sloped,white,font=\scriptsize]{24712}}

%Define special tracks (move to other commands) \newcommand{\wideAddition}{-- ++(\currentangle - 90:7.08) node[midway,sloped,white,font=\scriptsize]{24071}} \newcommand{\wideCorrection}{-- ++(\currentangle - 90:22.91) node[midway,sloped,white,font=\scriptsize]{24229}} \newcommand{\widelength}{-- ++(\currentangle - 90:23.61) node[midway,sloped,white,font=\scriptsize]{24236}}

%Define how tracks should appear \tikzset{ show track segments/.style={ decoration={ show path construction, moveto code={}, lineto code={ \draw [{Tee Barb[line width=1pt,inset=0pt,length=0pt,width=12]}-{Tee Barb[line width=1pt,inset=0pt,length=0pt,width=12]}] (\tikzinputsegmentfirst) -- (\tikzinputsegmentlast); }, curveto code={ \draw [{Tee Barb[line width=1pt,inset=0pt,length=0pt,width=12]}-{Tee Barb[line width=1pt,inset=0pt,length=0pt,width=12]}] (\tikzinputsegmentfirst) .. controls (\tikzinputsegmentsupporta) and (\tikzinputsegmentsupportb) ..(\tikzinputsegmentlast); }, closepath code={ \draw [{Tee Barb[line width=1pt,inset=0pt,length=0pt,width=12]}-{Tee Barb[line width=1pt,inset=0pt,length=0pt,width=12]}] (\tikzinputsegmentfirst) -- (\tikzinputsegmentlast); } },decorate }, lok links/.style={anchor=west,inner sep=0pt,outer sep=0pt} }

%Start drawing the layout \begin{document} \begin{tikzpicture}[scale=0.1]

%Measurements
\draw[<->,xshift=-10mm] (0,-330) -- (0,0) node[midway,sloped,above]{\SI{330}{\centi\metre}};
\draw[<->,yshift=10mm] (0,0) -- (330,0) node[midway,sloped,above]{\SI{330}{\centi\metre}};
\draw[<->,xshift=10mm] (337,-30) -- (337,0) node[midway,sloped,below]{$\leq\SI{30}{\centi\metre}$};
\draw[<->,yshift=-10mm] (0,-330) -- (30,-330) node[midway,sloped,below]{$\leq\SI{30}{\centi\metre}$};

%Surface
\fill[lightgray,text=red] (0,-330)node{1} -| ++(30,140)node{2} -- ++(-20,120)node{3} -- ++(40,40)node{4} -| ++(257,-110) -| ++(30,140)node{5} -| cycle;

%Layout
\draw[line width=4,orange,postaction=show track segments] (3,-67.36) \storeLocation{startpunkt}{0} \xxlR \xxlR \xxlR \wideSwitchR{StreckengleisHolzverladung} \double \double \double;

\draw[line width=4,orange,postaction=show track segments] \getLocation{StreckengleisHolzverladung} \single \single \single \wideL \wideSwitchL{gleis2} \wideAddition coordinate(gleis3Zughalt) \wideCorrection \wideAddition \wideCorrection \wideCorrection \wideAddition \widelength \single \storeLocation{prellbock}{180};

\draw[line width=4,orange,postaction=show track segments] \getLocation{prellbock} \single \wideSwitchR{prellbockweiche};

\draw[line width=4,orange,postaction=show track segments] \getLocation{prellbockweiche} \wideAddition \wideL;

\draw[line width=4,orange,postaction=show track segments] \getLocation{gleis2} \wideAddition \wideSwitchR{gleis1} \wideAddition \wideR \wideCorrection \wideAddition \widelength \single;

\draw[line width=4,orange,postaction=show track segments] \getLocation{gleis1} \wideAddition \wideCorrection;



\draw[line width=4,magenta,postaction=show track segments] \getLocationInverted{startpunkt} \wideSwitchL{gleisanschluss} \wideAddition \wideL \double \double \wideR \wideSwitchR{bahnhofgleis2} \wideAddition \wideR \double;

\draw[line width=4,blue,postaction=show track segments] \getLocation{gleisanschluss} \wideAddition \double \double;

\end{tikzpicture}

\end{document}

TobiBS
  • 5,240