TikZ 独立版在使用循环时无法生成布局紧密的 PDF

TikZ 独立版在使用循环时无法生成布局紧密的 PDF

当我尝试在代码中添加循环时发生了一些非常奇怪的事情(它们实际上并不是真正的循环,而是从一个节点到自身的边,由inout参数控制。

以下是我正在处理的代码(查找---> [Comment]出现问题的行:

\documentclass[tikz,multi]{standalone}
\usepackage{color,xcolor}
\usepackage{tikz}
\usetikzlibrary{arrows.meta,
                shapes,
                positioning,
                decorations.pathmorphing} 
  
%% My "standalone" scheme by TikZ
\begin{document}

\begin{tikzpicture}
%% Nodes
\draw (0,0) node (origin) {};
\node[at=(origin.center),circle, minimum size=2cm,draw=black] (x) {X};
% %% Loops ---> THIS MAKES THE BOUNDING BOX NOT TIGHT
\path (x) edge[->,out=250,in=150,min distance=0.25cm,looseness=5] node[very near end, below right]{\bf\Huge{-}}(x);
\end{tikzpicture}

\end{document}

如何避免此问题并自动获取没有白边的 PDF,并且不可能在外面或后期处理中裁剪它?

我正在用 Overleaf 运行这段代码,所以应该没有软件错误;相反,应该只是我做错了。谢谢。

答案1

您可以使用像这样bbox提供的 tikz 库bezier bounding box

\documentclass[tikz, border=1cm]{standalone}
\usetikzlibrary{bbox}
\begin{document}
\begin{tikzpicture}[bezier bounding box]
\node[circle, draw, ultra thick] (activity) {X};
\draw (activity) to[out=110, in=220, min distance=0.25cm, looseness=5] (activity);
\draw[red, dashed] (current bounding box.south west) rectangle (current bounding box.north east);
\node at (0,1) {Bezier bounding box};
\end{tikzpicture}
\begin{tikzpicture}
\node[circle, draw, ultra thick] (activity) {X};
\draw (activity) to[out=110, in=220, min distance=0.25cm, looseness=5] (activity);
\draw[red, dashed] (current bounding box.south west) rectangle (current bounding box.north east);
\node at (0,2) {Normal bounding box};
\end{tikzpicture}
\end{document}

带有环路和紧密红色矩形的节点 带有环和松散红色矩形的节点

相关内容