3

I would like to draw two lines side by side, like this:

two lines side by side

It's difficult to draw them separately when the lines are bended in some place. I tried the double option, but it would bring three lines.

This is my code (draw the two lines separately):

\documentclass{standalone}
\usepackage{tikz}
\begin{document}
\definecolor{line3}{cmyk}{0.02,0.16,1,0}
\definecolor{line4}{cmyk}{0.86,1,0.03,0.01}
\begin{tikzpicture}
\draw[color=line3,line width=5pt,rounded corners] (0,0) -- ++(1.05,1.05) -- ++(1,0);
\draw[color=line4,line width=5pt,rounded corners] (3.535pt,-3.535pt) -- ++(1,1) -- ++(1,0);
\end{tikzpicture}
\end{document}
JitByam
  • 33

1 Answers1

4

The following example draws the line twice. First the full line is drawn with the lighter color. Then the the path is used to make a clip region for the lower part. Then the full line is drawn with the darker color:

\documentclass{standalone}
\usepackage{tikz}
\definecolor{line3}{cmyk}{0.02,0.16,1,0}
\definecolor{line4}{cmyk}{0.86,1,0.03,0.01}
\begin{document}
\begin{tikzpicture}
  \begin{scope}[
    line width=10pt,
    rounded corners,
  ]
    \def\mypath{(0, 0) -- ++(1, 1) -- ++(1, 0)}
    \draw[color=line3] \mypath;
    \begin{scope}[overlay]
      \clip (-1, -1) -- \mypath -- ++(1, 0) -- ++(0, -2) -- cycle;
      \draw[color=line4] \mypath;
    \end{scope}
  \end{scope}
\end{tikzpicture}
\end{document}

Result

Heiko Oberdiek
  • 271,626
  • Is there a better solution using postaction (as in https://imathworks.com/tex/tex-latex-two-parallel-curved-edges-in-tikz-or-one-curved-edge-with-two-colors-side-by-side/) ? The trick in the link doesn't seem to work for straight lines unfortunately. – Cyriac Antony May 15 '23 at 14:39