This is not exactly what you asked for, but I think it is pretty close. The only downside is that you need to use two, rather than one, \draw lines per path. The first uses outlined track and the second track. Both styles use a slightly modified version of Mark Wibrow's answer.
\begin{tikzpicture}
\draw[outlined track] (0,0) to (10,0);
\draw[track] (0,0) to (10,0);
\begin{scope}[shift=(-45:4)]
\draw [outlined track] (-2,5) to (0,5) to[out= 0,in=270] (2,8);
\draw [track] (-2,5) to (0,5) to[out= 0,in=270] (2,8);
\draw [outlined track] (6,5) to (4,5) to[out=180,in=270] (2,8) to (2,10);
\draw [track] (6,5) to (4,5) to[out=180,in=270] (2,8) to (2,10);
\end{scope}
\end{tikzpicture}
I think the result is not bad in terms of the output:

Ideally, a little more would be automated, but the basic idea seems fairly sound. Essentially, we first draw a slightly enlarged version of the tracks in the outlining colour (black by default) and then draw a normally-sized version in the filling colour (gray by default). Done this way, we can also include the sleepers by adjusting the dash pattern definition used in the tracks decoration's code. First, we adjust the on-off pattern to allow for the different sizes of the thicker outlining lines and the thinner filling lines. Then we use dash phase to offset it appropriately in similar fashion.
This is all very trivial. The code is essentially Mark's - I've just added a few more keys, another style and a very small amount of flexibility to the part of the decoration responsible for the sleepers.
\documentclass[border=10pt]{standalone}
\usepackage{tikz}
\usepackage{pagecolor}
% addaswyd o ateb Mark Wibrow: https://tex.stackexchange.com/a/198114/
\usetikzlibrary{decorations,fit,fadings}
% Layers
\pgfdeclarelayer{sleeper}
\pgfdeclarelayer{rail}
\pgfsetlayers{sleeper,rail,main}
\pgfdeclaredecoration{tracks}{final}{%
\state{final}{%
\pgftransformreset% <- I think is possibly vital.% <- cfr: why?
%
% Get bounding box of decorated path as a node.
% Must do it this way using basic layer.
\pgftransformshift{\pgfpointanchor{current path bounding box}{south west}}%
\pgfcoordinate{@1}\pgfpointorigin
\pgftransformshift{\pgfpointanchor{current path bounding box}{north east}}%
\pgfcoordinate{@2}\pgfpointorigin
\node [fit=(@1)(@2), inner sep=\railsep+2*\railwidth] (@@) {};
%
% Create a fading for the track.
\pgfinterruptpicture%
\begin{tikzfadingfrompicture}[name=tracks]
\path[draw=transparent!0, line width=\railsep+2*\railwidth, postaction={draw=transparent!100, line width=\railsep}] \pgfextra{\pgfsetpath\pgfdecoratedpath};
\useasboundingbox (@@.south west) (@@.north east);
\end{tikzfadingfrompicture}%
\endpgfinterruptpicture
%
% Draw sleepers.
\ifx\sleeperlayer\emptylayer\else\pgfonlayer{\sleeperlayer}\fi
\draw [draw=\sleepercolor, line width=\sleeperlength, dash pattern=on \sleeperwidth off {\sleepersep-\sleeperwidth+\sleeperowidth}, dash phase={0.5*(\sleeperwidth-\sleeperowidth)}, every sleeper/.try] \pgfextra{\pgfsetpath\pgfdecoratedpath};
\ifx\sleeperlayer\emptylayer\else\endpgfonlayer\fi
%
% Draw the track
\ifx\raillayer\emptylayer\else\pgfonlayer{\raillayer}\fi
\fill [path fading=tracks, fit fading=false, fading transform={shift=(@@.center)}, fill=\railcolor] (@@.south west) rectangle (@@.north east);
\ifx\raillayer\emptylayer\else\endpgfonlayer\fi
}
}
\def\emptylayer{}
\tikzset{%
track/.style={
decoration=tracks, decorate
},
outlined track/.style={
track,
decorations/.cd,
rail width=\railowidth,
rail sep=\railisep,
rail color=\raildraw,
sleeper color=\sleeperdraw,
sleeper width=\sleeperowidth,
},
decorations/.cd,
rail sep/.store in=\railsep,
rail inner sep/.store in=\railisep,
rail width/.store in=\railwidth,
rail inner width/.forward to=/tikz/decorations/rail width,
rail outer width/.store in=\railowidth,
rail color/.store in=\railcolor,
rail draw/.store in=\raildraw,
rail layer/.store in=\raillayer,
sleeper sep/.store in=\sleepersep,
sleeper width/.store in=\sleeperwidth,
sleeper inner width/.store in=\sleeperiwidth,
sleeper inner width/.forward to=/tikz/decorations/sleeper width,
sleeper outer width/.store in=\sleeperowidth,
sleeper length/.store in=\sleeperlength,
sleeper color/.store in=\sleepercolor,
sleeper draw/.store in=\sleeperdraw,
sleeper layer/.store in=\sleeperlayer,
rail sep=4pt,
rail inner sep=3pt,
rail inner width=1pt,
rail outer width=2pt,
rail color=gray,
rail draw=black,
rail layer=rail,
sleeper sep=6pt,
sleeper inner width=1pt,
sleeper outer width=2pt,
sleeper length=10pt,
sleeper color=gray,
sleeper draw=black,
sleeper layer=sleeper,
}
\begin{document}
\pagecolor{yellow}
\begin{tikzpicture}
\draw[outlined track] (0,0) to (10,0);
\draw[track] (0,0) to (10,0);
\begin{scope}[shift=(-45:4)]
\draw [outlined track] (-2,5) to (0,5) to[out= 0,in=270] (2,8);
\draw [track] (-2,5) to (0,5) to[out= 0,in=270] (2,8);
\draw [outlined track] (6,5) to (4,5) to[out=180,in=270] (2,8) to (2,10);
\draw [track] (6,5) to (4,5) to[out=180,in=270] (2,8) to (2,10);
\end{scope}
\end{tikzpicture}
\end{document}
tikzwork a cascade ofpostactionshere is wrong (dead end) way. – Zarko Mar 03 '18 at 20:30postactionaccumulate? i doubt (don't know). i thing that on power is the last one. – Zarko Mar 03 '18 at 20:32Also, I don't like how the sleepers curve in Mark Wibrow's code, but as I am going to produce then in a different way, that doesn't matter too much. Anyway, if someone could show me how to edit his code to get my wanted results, that would be awesome too (with or without sleepers).
– Lukas Mar 03 '18 at 21:40