让我们假设以下情况(这是我能想到的最简单的情况):一个圆与一条线的两个不同点相交,我们将这些点称为 C 和 D。
\documentclass[a4paper, 10pt]{article}
\usepackage{tikz}
\usetikzlibrary{intersections}
\begin{document}
And here we've got a text about whatever it's talking about and probably is introducing this:
\begin{figure}[h!]
\centering
\begin{tikzpicture}
\coordinate (A) at (-2,0);
\coordinate (B) at (2,0);
\coordinate (P) at (0,1);
\draw [name path=line] (A)--(B);
\draw [name path=circle] (P) circle (1.5cm);
\path [name intersections ={of=line and circle,name=N,total=\t}];
\node at (N-1)[below left]{C};
\node at (N-2)[below right]{D};
\end{tikzpicture}
\end{figure}
Which lead us to the meaning of the figure.
\end{document}
我的情况实际上使用了 through 库,在示例中,就像给出线的一个点(C 或 D)并从 P 处通过该点绘制一个圆。我真的不知道它是否能改变问题。问题是:如果我只想要坐标怎么办?我不会使用 \draw,而是使用 \path(或 \node at (?) [circle through (...)];)和任何命令来简单地获取坐标。在示例中,我只是切换\draw [name path=circle] (P) circle (1.5cm);
到\path [name path=circle] (P) circle (1.5cm);
\documentclass[a4paper, 10pt]{article}
\usepackage{tikz}
\usetikzlibrary{intersections}
\begin{document}
And here we've got a text about whatever it's talking about and probably is introducing this:
\begin{figure}[h!]
\centering
\begin{tikzpicture}
\coordinate (A) at (-2,0);
\coordinate (B) at (2,0);
\coordinate (P) at (0,1);
\draw [name path=line] (A)--(B);
\path [name path=circle] (P) circle (1.5cm);
\path [name intersections ={of=line and circle,name=N,total=\t}];
\node at (N-1)[below left]{C};
\node at (N-2)[below right]{D};
\end{tikzpicture}
\end{figure}
Which lead us to the meaning of the figure.
\end{document}
这个巨大的空白区域。如何消除它才能得到如下效果:
顺便说一下,对于最后一幅图像,我只是输入了 C 和 D 坐标作为它们两个实际 X 坐标的近似值。
答案1
即使没有绘制路径,它们仍会对边界框产生影响。因此,您可能需要overlay
在辅助路径和坐标上使用键。overlay
确保它们不会对边界框产生影响。
\documentclass[a4paper, 10pt]{article}
\usepackage{tikz}
\usetikzlibrary{intersections}
\begin{document}
And here we've got a text about whatever it's talking about and probably is introducing this:
\begin{figure}[h!]
\centering
\begin{tikzpicture}
\path (-2,0) coordinate (A) (2,0) coordinate (B);
\path[overlay] (0,1) coordinate (P);
\draw [name path=line] (A)--(B);
\path[overlay,name path=circle] (P) circle[radius=1.5cm];
\path [name intersections ={of=line and circle,name=N}];
\node at (N-1)[below left]{C};
\node at (N-2)[below right]{D};
\end{tikzpicture}
\end{figure}
Which lead us to the meaning of the figure.
\end{document}
答案2
另一种方法是重置边界框并重新创建它以仅包含特定节点和范围(使用本地边界框)。
\documentclass[a4paper, 10pt]{article}
\usepackage{tikz}
\usetikzlibrary{intersections,fit}
\begin{document}
And here we've got a text about whatever it's talking about and probably is introducing this:
\begin{figure}[h!]
\centering
\begin{tikzpicture}
\coordinate (A) at (-2,0);
\coordinate (B) at (2,0);
\coordinate (P) at (0,1);
\draw [name path=line] (A)--(B);
\path [name path=circle] (P) circle (1.5cm);
\path [name intersections ={of=line and circle,name=N,total=\t}];
\node (C) at (N-1)[below left]{C};
\node (D) at (N-2)[below right]{D};
\pgfresetboundingbox
\node[fit=(A) (B) (C) (D)] {};
\draw[red] (current bounding box.south west) rectangle (current bounding box.north east);
\end{tikzpicture}
\end{figure}
Which lead us to the meaning of the figure.
\end{document}