Here's an alternative. It uses the same basic idea as Frederic's in that it replaces the doubling by a preaction (doubling really is just a preaction except for a little trickery to handle arrows). But instead of shortening the underlying path, it draws it on a background layer. The method of doing that is to encase the preaction path in a \pgfonlayer ... \endpgfonlayer
sandwich. This requires a new key, which I've imaginatively called preaction on background layer
. It has to go after the preaction has been defined as it encases the currently defined preaction in the appropriate commands - it can't act presumptively. Although I've put it in to its own style option, you'd want to be able to specify the colour and line width in a similar fashion to the double
syntax. That wouldn't be hard to do.
Here's the code (with, for comparison, the original double
, Frederic's version, and my version all in a row):
\documentclass{standalone}
\usepackage{tikz}
\pgfdeclarelayer{background}
\pgfsetlayers{background,main}
\makeatletter
\def\pgf@on@bglayer{\pgfonlayer{background}}
\tikzset{
preaction on background layer/.code={
\expandafter\def\expandafter\tikz@preactions\expandafter{\expandafter\pgf@on@bglayer\tikz@preactions\endpgfonlayer}
},
double behind/.style={
preaction={
draw,
red,
line width=8pt
},
preaction on background layer
}
}
\makeatother
\begin{document}
\begin{tikzpicture}
\foreach \ang in {45,90,...,360} {
\draw[line width=2pt,red,double=black,double distance=4pt] (0,0) -- (\ang:2);
}
\foreach \ang in {45,90,...,360} {
\draw[black,line width=4pt,preaction={line width=8pt,red,draw,shorten >=2pt,shorten <=2pt}] (5,0) -- ++(\ang:2);
}
\foreach \ang in {45,90,...,360} {
\draw[double behind,line width=4pt] (10,0) -- ++(\ang:2);
}
\end{tikzpicture}
\end{document}
And the result:
(Incidentally, Frederic's solution would have been my first choice as well, if it weren't for his remark about the curved lines being off.)
shorten >
/shorten <
options to further shorten the line. There is thespace
arrow head which simply shortens the line. One problem I just figured out is that the arrow heads are drawn with the main color, not with the inner color.