为什么 TikZ 忽略了我设置边界框的指示?

为什么 TikZ 忽略了我设置边界框的指示?

下面图片的边界框是错误的(尽管我试图设置它)

\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}

答案1

边界框比我们想象的要大,因为\tkzInterCC[R](A,2.75in)(B,2.75in)构造了影响边界框的不可见路径。您\path [use as bounding box]无法修复该问题的原因是它use as bounding box不会减小当前边界框的大小,而只是导致在确定边界框时忽略所有后续路径。

实现所需结果的两种方法:

  1. 通过将有问题的命令包装在环境中,使它不影响边界框pgfinterruptboundingbox

    \begin{pgfinterruptboundingbox}
      \tkzInterCC[R](A,2.75in)(B,2.75in) 
    \end{pgfinterruptboundingbox}
    
  2. use as bounding box在发出命令之前使用以下命令重置边界框\pgfresetboundingbox

    \pgfresetboundingbox
    \path [use as bounding box] ($(A)-(offset)$) rectangle ($(D)+(offset)$);
    

相关内容