4

Assumed we have this very simple Minimum Working Example (MWE) to draw a straight line:

\documentclass[tikz]{standalone}
\usetikzlibrary{intersections,decorations.pathmorphing}

\begin{document}
    \begin{tikzpicture}
        \draw[draw=red, line width=5pt]   (-10,6) -- (50,6);
    \end{tikzpicture}
\end{document}

Screenshot of the result:

Screenshot of the result

As you can see, the line reaches the left and right page borders of the TikZ-layout as desired.


However, if I edit the upper MWE and add a seam allowance to create a second (parallel) line, the left and right page borders will suddenly increase:

\documentclass[tikz]{standalone}
\usetikzlibrary{intersections,decorations.pathmorphing}

\begin{document}

    \tikzset{%
      seam/.style={double distance=\seamallowance,draw},%
      seam allowance/.store in=\seamallowance,%
      seam allowance=5cm,%
    }

    \begin{tikzpicture}
        \draw[seam, draw=red, line width=5pt]   (-10,6) -- (50,6);
    \end{tikzpicture}

\end{document}

Screenshot of the result:

Screenshot of the false behavior

As you can see, those ugly white spaces on the left and right side have appeared.


Question:

How can I avoid this behavior, so the new line won't create any additional white space on the sides anymore?

  • 1
    You have whitespace in the first example as well, but just a little bit. I think this has to do with the line caps. If you set line cap=rect you won't get the whitespace, but you will also get a red rectangle, not just red lines on the top and bottom, so that doesn't really help. – Torbjørn T. Jul 20 at 7:29
6

The background of the bounding box calculation is described in tikz: double lines are shifted.

The solution from Loop Space works here too, but you need to add a piece of the line as a path to avoid that standalone gets confused when the tikzpicture has suddenly no height anymore:

\documentclass[tikz]{standalone}
\usepackage{tikz}
\usetikzlibrary{intersections,decorations.pathmorphing}
\makeatletter
\tikzset{
  only coordinates are relevant/.is choice,
  only coordinates are relevant/.default=true,
  only coordinates are relevant/true/.code={%
    \tikz@addmode{\pgf@relevantforpicturesizefalse}},
  only coordinates are relevant/false/.code={%
    \tikz@addmode{\pgf@relevantforpicturesizetrue}}
}
\makeatother
\begin{document}

    \tikzset{%
      seam/.style={double distance=\seamallowance,draw,},%
      seam allowance/.store in=\seamallowance,%
      seam allowance=5cm,%
    }

    \begin{tikzpicture}
        \path[seam,line width=5pt]   (10,6); %so that the picture has the correct height ...
        \draw[seam, draw=red, line width=5pt,only coordinates are relevant]   (-10,6) -- (50,6);
    \end{tikzpicture}

\end{document} 

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.