18

I need to be able to draw tripled paths in TikZ. I guess this could be done by some clever style which draws a big doubled path to get the outer curves correct, then uses some clever post-action hackery to draw a second non-doubled path to produce the central curve. I need to be able to set the thickness and the spacings of the three lines independently, just like one can with doubled lines.

Luckily, I don't need arrowheads on the line!

Anyone up to the challenge? :)

  • Just to be clear, the idea is that the three lines will be evenly spaced. So there are two parameters I want to be able to supply: the width of the individual curves, and the separation between adjacent curves. – Jamie Vicary Dec 15 '11 at 21:21
  • And by using the term "path", you mean that this is not just a straight line, but a number of connected line segments, possibly with rounded edges/curves at each connection. And, no pstricks? – Werner Dec 15 '11 at 21:26
  • Hi Werner. I need to end up with a PDF - does that rule out pstricks? Maybe that's a stupid question. I'm not sure what the pros and cons are of that option. But anyway, yes, it's a fully-general path. I'll need to use the \draw [triple] (A) to [out=45,in=100] (B) construction and its ilk. – Jamie Vicary Dec 15 '11 at 21:32
  • pstricks can also be used to produce PDF output via a different compiling sequence or pst-pdf. – Werner Dec 15 '11 at 21:40
  • 1
    The arrowheads would have been what made this interesting ... (actually, I do have a solution for that; just waiting for someone to ask the right question) – Loop Space Dec 15 '11 at 22:38
20

So basically a pre action on the path. I have added a style which is shown how to be called, notice that it will always draw.

\documentclass{article}
\usepackage{tikz}
\begin{document}
\tikzset{
    triple/.style args={[#1] in [#2] in [#3]}{
        #1,preaction={preaction={draw,#3},draw,#2}
    }
}        
\begin{tikzpicture}
  \draw[triple={[line width=1mm,red] in
      [line width=2mm,blue] in
      [line width=4mm,black]}] (0,0) to[out=10,in=100] (0,1);
\end{tikzpicture}
\end{document}
  • Perhaps I should wait for more answers, but that seems to do the job! Thanks! – Jamie Vicary Dec 15 '11 at 21:35
  • @JamieVicary, yes that should at least attract other users who might drop in on a solution. – zeroth Dec 15 '11 at 21:47
  • I adapted your code to produce this, which works very well for my purposes: – Jamie Vicary Dec 15 '11 at 21:48
  • \newlength\triplesep \newlength\triplelinewidth \setlength\triplesep{1pt} \setlength\triplelinewidth{1pt} \tikzset{triple/.style={line width=\triplelinewidth,black, preaction={ preaction={draw,line width=2\triplesep+3\triplelinewidth,black}, draw,line width=2\triplesep+\triplelinewidth,white} } } – Jamie Vicary Dec 15 '11 at 21:48
  • Oops, wasn't expecting it to look like that ... anyway, maybe it'll be useful for someone :). – Jamie Vicary Dec 15 '11 at 21:49
3

enter image description here

\documentclass[pstricks,border=12pt]{standalone}
\usepackage{pstricks}


\begin{document}


\begin{pspicture}(5,5)
    \rput(2.5,4){Step 1}
    \psline[linewidth=5pt](5,5)
\end{pspicture}


\begin{pspicture}(5,5)
    \rput(2.5,4){Step 2}
    \psline[border=1pt,bordercolor=yellow,linewidth=1pt](5,5)
\end{pspicture}


\begin{pspicture}(5,5)
    \rput(2.5,4){Step 3}
    \psline[linewidth=5pt](5,5)
    \psline[border=1pt,bordercolor=yellow,linewidth=1pt](5,5)
\end{pspicture}

\end{document}
  • which parameter setting do you use for the gif. I tried: convert -delay 50 -loop 0 -density 150 -alpha off <file>.pdf <file>.gif but the output is lousy ... – user2478 Aug 27 '12 at 16:13
  • convert: UnrecognizedAlphaChannelType remove' @ error/convert.c/ConvertImageCommand/657. I have ImageMagick 6.7.2-7 2012-04-26 Q16. – user2478 Aug 27 '12 at 16:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.