6

Consider the following MWE:

\documentclass[border=5pt]{standalone}

\usepackage{tikz}

\begin{document}

\begin{tikzpicture}
   \draw (0,0)  circle (1);
   \draw[blue] (current bounding box.south west) rectangle 
        (current bounding box.north east);
\end{tikzpicture}\quad
%
\begin{tikzpicture}
   \draw (0,0)  circle (1);
   \draw[red] (200:1)  arc (200:320:1);
   \draw[blue] (current bounding box.south west) rectangle 
        (current bounding box.north east);
\end{tikzpicture}\quad
%
\begin{tikzpicture}
   \draw (0,0)  circle (1);
   \draw[green] (320:1)  arc (320:560:1);
   \draw[blue] (current bounding box.south west) rectangle
        (current bounding box.north east);
\end{tikzpicture}\quad
%
\begin{tikzpicture}
   \draw[red] (200:1)  arc (200:320:1);
   \draw[green] (320:1)  arc (320:560:1);
   \draw[blue] (current bounding box.south west) rectangle
        (current bounding box.north east);
\end{tikzpicture}\quad
%
\begin{tikzpicture}
   \draw[green] (320:1)  arc (320:560:1);
   \draw[blue] (current bounding box.south west) rectangle
        (current bounding box.north east);
\end{tikzpicture}\quad
%
\begin{tikzpicture}
   \draw[red] (200:1)  arc (200:320:1);
   \draw[blue] (current bounding box.south west) rectangle
        (current bounding box.north east);
\end{tikzpicture}

\end{document}

I would expect the bounding box to fit tightly around the arcs. However, the picture shows a different behavior. I am sure there are experts around here who can explain me why this happens....

enter image description here

7

When TikZ calculates the bounding box for an arc, it uses the start, end and control points of the Bezier curves into account. The control points usually lie outside the arc.

The following example fixes the bounding boxes by a reset of the bounding box \pgfresetboundingbox and setting it again with a \draw command without lines using some points that define the bounding box. \draw is used instead of \path or \useasboundingbox, because it also takes the line width into account.

\documentclass[border=5pt]{standalone}

\usepackage{tikz}

\begin{document}

\begin{tikzpicture}
   \draw (0,0)  circle (1);
   \draw[blue] (current bounding box.south west) rectangle
        (current bounding box.north east);
\end{tikzpicture}\quad
%
\begin{tikzpicture}
   \draw (0,0)  circle (1);
   \draw[red] (200:1)  arc (200:320:1);
   \pgfresetboundingbox
   \draw (-1, -1) (1, 1);
   \draw[blue] (current bounding box.south west) rectangle
        (current bounding box.north east);
\end{tikzpicture}\quad
%
\begin{tikzpicture}
   \draw (0,0)  circle (1);
   \draw[green] (320:1)  arc (320:560:1);
   \pgfresetboundingbox
   \draw (-1, -1) (1, 1);
   \draw[blue] (current bounding box.south west) rectangle
        (current bounding box.north east);
\end{tikzpicture}\quad
%
\begin{tikzpicture}
   \draw[red] (200:1)  arc (200:320:1);
   \draw[green] (320:1)  arc (320:560:1);
   \pgfresetboundingbox
   \draw (-1, -1) (1, 1);
   \draw[blue] (current bounding box.south west) rectangle
        (current bounding box.north east);
\end{tikzpicture}\quad
%
\begin{tikzpicture}
   \draw[green] (320:1)  arc (320:560:1);
   \pgfresetboundingbox
   \draw (-1, 1) (1, 0) (320:1);
   \draw[blue] (current bounding box.south west) rectangle
        (current bounding box.north east);
\end{tikzpicture}\quad
%
\begin{tikzpicture}
   \draw[red] (200:1)  arc (200:320:1);
   \pgfresetboundingbox
   \draw (0, -1) (200:1) (320:1);
   \draw[blue] (current bounding box.south west) rectangle
        (current bounding box.north east);
\end{tikzpicture}

\end{document}

Result

  • (+1) for giving me something useful to look up ;). But within a pic, for example, \pgf@relevantforpicturesizefalse is useful. (I freely concede this question had nothing at all to do with pics.)And the fit library can be useful if you have something less predictable than a circle. An extraterrestrial, say, or something like that ;). – cfr Feb 26 '16 at 18:21

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.