为什么装饰标记不会延伸 TikZ 图片的边界框?我该如何改变这种情况?请考虑这个箭头标记被部分裁剪的例子。
\documentclass[tikz]{standalone}
\usetikzlibrary{decorations.markings}
\tikzset{
loop/.style 2 args={thick,decoration={markings,mark=at position {#1} with {\arrow{>},\node[anchor=\pgfdecoratedangle-90,font=\footnotesize,] {$p_{#2}$};}},postaction={decorate}}
}
\begin{document}
\begin{tikzpicture}[pin edge={shorten <=5*\lrad}]
\draw[loop/.list={{0.25}{1},{0.75}{2}}] (0,0) circle (1);
\end{tikzpicture}
\end{document}
答案1
默认箭头不会更新边界框。但是arrows.meta
库中较新、更复杂的箭头做更新边界框。添加\usetikzlibrary{arrows.meta}
到前言部分基本可以解决问题,但如果箭头包含rect
或round
线帽,则可能需要额外的边框。
\documentclass[tikz]{standalone}
\usetikzlibrary{decorations.markings}
\usetikzlibrary{arrows.meta}
\tikzset{
loop/.style 2 args={
thick,
decoration={
markings,
mark=at position {#1} with {\arrow{>},
\node[anchor=\pgfdecoratedangle-90,font=\footnotesize,]{$p_{#2}$};}
},
postaction={decorate}
}
}
\begin{document}
\begin{tikzpicture}[pin edge={shorten <=5*\lrad}]
\draw[loop/.list={{0.25}{1},{0.75}{2}}] (0,0) circle (1);
\end{tikzpicture}
\end{document}