8

I want two make same space between two smooth curves enter image description here

\documentclass[12pt]{article}
\usepackage{tikz}
\usetikzlibrary{calc}
\begin{document}
\begin{tikzpicture}
\coordinate  (O) at (0,0);
\draw [thick]  plot[smooth, tension=.7] coordinates {(-4,2.5) (-3,3) (-2,2.8) (-0.8,2.5) (-0.5,1.5) (0.5,0) (0,-2)(-1.5,-2.5) (-4,-2) (-3.5,-0.5) (-5,1) (-4,2.5)};
\draw (-1,0)[thick,scale=0.8]  plot[smooth, tension=.7] coordinates {(-4,2.5) (-3,3) (-2,2.8) (-0.8,2.5) (-0.5,1.5) (0.5,0) (0,-2)(-1.5,-2.5) (-4,-2) (-3.5,-0.5) (-5,1) (-4,2.5)};
\end{tikzpicture}
\end{document}
5

Same principle as David's answer. The lines can be drawn as double line with option double. The white space between is configured by option double distance.

The plot is closed, but it is drawn as open plot ending and starting at the same point. This causes unnecessary artifacts at this point. Removing the duplicate point and option smooth cycle fixes this.

Example:

\documentclass[12pt]{article}
\usepackage{tikz}
\usetikzlibrary{calc}
\begin{document}
\begin{tikzpicture}
\coordinate  (O) at (0,0);
\draw [
  double=white,
  double distance=20pt,
  thick,
]  plot[smooth cycle, tension=.7] coordinates {
  (-4,2.5) (-3,3) (-2,2.8) (-0.8,2.5) (-0.5,1.5)
  (0.5,0) (0,-2)(-1.5,-2.5) (-4,-2) (-3.5,-0.5) (-5,1)
};
\end{tikzpicture}
\end{document}

Result

The disadvantage of this approach is that the space between the lines is explicitly drawn in white color as can be seen in the image above.

  • I thought tikz would have a ready made option to do that somewhere;-) – David Carlisle Oct 28 '16 at 15:37
12

One way is not to draw two paths, but one path at two thicknesses

enter image description here

\documentclass[12pt]{article}
\usepackage{tikz}
\usetikzlibrary{calc}
\begin{document}
\begin{tikzpicture}
\coordinate  (O) at (0,0);
\draw [line width=10pt]  plot[smooth, tension=.7] coordinates {(-4,2.5) (-3,3) (-2,2.8) (-0.8,2.5) (-0.5,1.5) (0.5,0) (0,-2)(-1.5,-2.5) (-4,-2) (-3.5,-0.5) (-5,1) (-4,2.5)};
\draw [line width=5pt, white]  plot[smooth, tension=.7] coordinates {(-4,2.5) (-3,3) (-2,2.8) (-0.8,2.5) (-0.5,1.5) (0.5,0) (0,-2)(-1.5,-2.5) (-4,-2) (-3.5,-0.5) (-5,1) (-4,2.5)};

\end{tikzpicture}
\end{document}
  • What simplicity and elegance! – Denis Oct 28 '16 at 15:22
6

Provided your curve is sufficiently smooth and has no sharp corners then you can exploit Metapost's direction feature to do this. Here I have used Metapost wrapped in luamplib so compile with lualatex. The advantage compared to drawing with a thick pen and erasing the middle is that you can use different pens or patterns as I have shown.

enter image description here

The variable name scc was to remind me that it's a smooth closed curve...

\RequirePackage{luatex85}
\documentclass[border=5mm]{standalone}
\usepackage{luamplib}
\begin{document}
\mplibtextextlabel{enable}
\begin{mplibcode}
beginfig(1);
    path scc, inner, outer;
    scc = ( (-4.0, 2.5) .. 
            (-3.0, 3.0) .. 
            (-2.0, 2.8) .. 
            (-0.8, 2.5) .. 
            (-0.5, 1.5) .. 
            ( 0.5, 0.0) ..
            ( 0.0,-2.0) .. 
            (-1.5,-2.5) .. 
            (-4.0,-2.0) .. 
            (-3.5,-0.5) .. 
            (-5.0, 1.0) .. 
            cycle ) scaled 1cm;

    drawarrow scc;         

    s = 1/16;
    inner = for t=s step s until length(scc):
       unitvector direction t of scc scaled 6 rotated -90 shifted point t of scc ..
    endfor cycle;

    outer = for t=s step s until length(scc):
       unitvector direction t of scc scaled 6 rotated +90 shifted point t of scc ..
    endfor cycle;

    draw inner dashed evenly withcolor 2/3 blue;
    draw outer dashed withdots withcolor 1/2 red;

endfig;
\end{mplibcode}
\end{document}

Note that if the original path ran counter-clockwise you would need to reverse the signs of the rotations to get the inner and outer paths correctly.

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.