How can I add an enveloping border around the blue line in this MWE?

\draw[blue, line width=10pt](0,0)--(90:1.5)--(60:2.5)--(30:3.0); 

enter image description here

PS. I found out that something similar is possible with MetaPost in this previous answer https://tex.stackexchange.com/a/330016, but I'd like to know if this is also possible with Tikz.

  • 1
    Why not another line with thickness of 8pt inside, \draw[white, line width=8pt,shorten >=1pt,shorten <=1pt](0,0)--(90:1.5)--(60:2.5)--(30:3.0);
    – Salim Bou
    Jul 17, 2017 at 11:00
  • tikz offers the option [double] which does what @SalimBou proposes, it draws the path twice with two different thicknesses. However, it does not close the path ends. For that, you would have to construct a secondary path, along the lines of ($0+5pt$,0) -- (with calc library). If there is a way to automate that, I am unaware of it.
    – Huang_d
    Jul 17, 2017 at 12:13
  • What's an enveloping border? Around what? The picture? The line?
    – cfr
    Jul 17, 2017 at 15:29
  • @Huang_d You can shorten only the main path, though, which would have the same effect, I think. And do it in preaction (or postaction) rather than using double.
    – cfr
    Jul 17, 2017 at 15:32
  • 1
    @SalimBou Would you like to write up an answer? Aug 28, 2017 at 21:36

2 Answers 2


This is Salim Bou solution with negative shorten values and declared as a style which adds a preaction.

Style border has three parameters:lower line width, border width (applied to shorten) and color.

\begin{tikzpicture}[border/.style n args={3}{
    preaction={draw=#3, line width=#1, shorten <=-#2, shorten >=-#2}}]
\draw[blue, line width=10pt, border={14pt}{2pt}{green}](0,0)--(90:1.5)--(60:2.5)--(30:3.0); 

\draw[blue, line width=10pt, border={14pt}{2pt}{green}](3,0)rectangle++(2,3); 

\draw[blue, line width=10pt, border={14pt}{2pt}{green}] (7,1) circle(1cm);


enter image description here


A solution based on this answer. This answer comes with an Outline style, which has one argument, the distance from the center to the line to the contour. The width is then twice this length.


% based on https://tex.stackexchange.com/a/103088/121799

\pgfkeys{/pgf/decoration/contour distance/.code={%
    /pgf/decoration/contour name/.store in=\ContourName,
    /pgf/decoration/contour name=mycontour

\pgfdeclaredecoration{contour lineto}{start}
    \state{start}[next state=draw, width=0pt]{
    \state{draw}[next state=draw, width=\pgfdecoratedinputsegmentlength]{       
\tikzset{Outline/.style={ postaction={
        decoration={contour lineto, contour distance=-#1,contour name=mycontourA},draw=blue,
        decoration={contour lineto, contour distance=#1,contour name=mycontourB},draw=blue,

\draw[red,line width=10pt](0,0)--(90:1.5)--(60:2.5)--(30:3.0); 
\path[blue,very thick,Outline=5pt](0,0)--(90:1.5)--(60:2.5)--(30:3.0); 

\path[blue,line width=2pt,Outline=5pt](0,0)--(90:1.5)--(60:2.5)--(30:3.0); 
\path[blue,line width=4pt,Outline=10pt](0,0)--(90:1.5)--(60:2.5)--(30:3.0); 

enter image description here

NOTE: This works only with polygons which are not closed.

You must log in to answer this question.

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