6

Is it possible to decorate a path with just a thick colored line above or below it? In the following example I faked manually the result, but how can I do it with decorations? In particular I want to be able to choose the color and the line width and use the raise option of the decoration.

\documentclass{article}

\usepackage{tikz}
\usetikzlibrary{calc}
\begin{document}

\begin{tikzpicture}
   \coordinate (A) at (0,0);
   \coordinate (B) at (1,1);
   \coordinate (v) at ($(B) - (A)$);

   \path let \p1 = (v) in ($1/(\x1^2 + \y1^2)^(0.5)*(\y1,-\x1)$) coordinate (p);
   \pgfmathsetmacro{\dist}{0.7}
   \coordinate (AA) at ($(A) + \dist*(p)$);
   \coordinate (BB) at ($(B) + \dist*(p)$);

   \draw (A) -- (B);
   \draw[thick,orange] (AA) -- (BB);
\end{tikzpicture}
\end{document}

output

Edit: If it is not possible to get it via decorations is it possible to define a style just for straight lines which allows you to draw two or three colored lines just like here: https://tex.stackexchange.com/a/36858/4011 in the case of circles.

8
  • Do you want this to work with curves and polygons, or just with straight lines?
    – Jake
    Oct 8, 2012 at 12:46
  • For my current application I want it only for straight lines.
    – student
    Oct 8, 2012 at 12:50
  • But if it is possible to do it with decorations, then it should automatically work with arbitrary path's...?
    – student
    Oct 8, 2012 at 12:51
  • Take a look at: tex.stackexchange.com/q/29991/86 Is that the sort of thing you are after? Oct 8, 2012 at 12:53
  • @AndrewStacey Thanks, but I think this doesn't really help. I want to know how to do it with decorations and the inside-outside problem doesn't matter in my case...
    – student
    Oct 8, 2012 at 13:00

1 Answer 1

2

Will using double help here?

\documentclass{standalone}
\usepackage[svgnames]{xcolor}
\usepackage{tikz}
\usetikzlibrary{calc}
\begin{document}

\begin{tikzpicture}
   \coordinate (A) at (0,0);
   \coordinate (B) at (1,1);
   \coordinate (v) at ($(B) - (A)$);

   \path let \p1 = (v) in ($1/(\x1^2 + \y1^2)^(0.5)*(\y1,-\x1)$) coordinate (p);
   \pgfmathsetmacro{\dist}{0.7}
   \coordinate (AA) at ($(A) + \dist*(p)$);
   \coordinate (BB) at ($(B) + \dist*(p)$); 
   \draw[line width=5pt,orange,double=black,double distance=1pt] (AA) -- (BB);

   \begin{scope}[xshift=4cm]
   \draw[very thick, orange,double=black,double distance=1pt] (-0.1,5) .. controls (-4,-2) and (4,-2) .. (0.1,5);
   \end{scope}

\end{tikzpicture}
\end{document}

enter image description here

1
  • 3
    Thanks. The problem with double is that then I get the colored line on both sides.
    – student
    Oct 8, 2012 at 16:13

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .