16

The bounding box for the following image is wrong (even though I've tried to set it)

\documentclass{article}
\usepackage[margin=0.25in]{geometry}
\usepackage{tikz}
\usetikzlibrary{calc}
\usepackage{tkz-euclide}
\pagestyle{empty}
\begin{document}

\begin{tikzpicture}[every node/.style={circle,inner sep=2pt,fill}]
  \coordinate (A) at (0,0);
  \coordinate (B) at (2.5in,0);  

  \coordinate (mAB) at ($(A)!0.5!(B)$);
  \coordinate (uAB) at (mAB) ++ (0,1);

  \tkzInterCC[R](A,2.75in)(B,2.75in) 
  \tkzGetPoints{C}{D}

  \draw (A) -- (B) -- (C) -- cycle;

  \node at (A) {};
  \node at (B) {};
  \node at (C) {};

  \node[fill=none] at ($(A)+(-90:2ex)$) {$N$};
  \node[fill=none] at ($(B)+(-90:2ex)$) {$M$};
  \node[fill=none] at ($(C)+(+90:2ex)$) {$Q$};

  \coordinate (D) at ($(A)!2.15!(C)$);
  \draw (A) -- (D);

  \coordinate (offset) at (0.25,0.25);
  \path [use as bounding box] ($(A)-(offset)$) rectangle ($(D)+(offset)$);
  \draw (current bounding box.north east) rectangle (current bounding  box.south west);

\end{tikzpicture}

\end{document}
A.Ellett
  • 50,533

1 Answers1

23

The bounding box is larger than one would think because the \tkzInterCC[R](A,2.75in)(B,2.75in) constructs invisible paths that influence the bounding box. The reason why your \path [use as bounding box] doesn't fix the problem is that use as bounding box does not reduce the size of the current bounding box, it merely causes all following paths to be ignored when determining the bounding box.

Two ways to achieve the desired result:

  1. Make the offending command not influence the bounding box by wrapping it in a pgfinterruptboundingbox environment:

    \begin{pgfinterruptboundingbox}
      \tkzInterCC[R](A,2.75in)(B,2.75in) 
    \end{pgfinterruptboundingbox}
    
  2. Reset the bounding box before issuing your use as bounding box command using \pgfresetboundingbox:

    \pgfresetboundingbox
    \path [use as bounding box] ($(A)-(offset)$) rectangle ($(D)+(offset)$);
    
Jake
  • 232,450