# Decoration markings don't extend bounding box

How come decoration markings don't extend a TikZ picture's bounding box and how can I change this? Consider this example where the arrow markings are partially cropped.

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


• – Ignasi Sep 27 '17 at 17:24

## 2 Answers

The default arrows do not update the bounding-box. But the newer more sophisticated arrows from the arrows.meta library do update the bounding box. Adding \usetikzlibrary{arrows.meta} to the preamble pretty much solves the problem, although an additional border may be needed if the arrow contains rect or round line caps.

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


• @Mark Wibrow Note that this also increases the arrow head size quite a bit. – Casimir Sep 27 '17 at 15:22
• @Casimir try adding >={Classical TikZ Rightarrow} to the tikzpicture options for the default arrow. Other arrows may need customising which is quite simple, e.g., >={Stealth[length=5pt]}. – Mark Wibrow Sep 27 '17 at 15:53

Pass the margin option within the class:

\documentclass[tikz,margin=3pt]{standalone}


• I know about the margin (and border) option. I'm wondering, why this is not handled correctly by default. It seems like there should be a "proper" way to fix this rather than manually adding a border. – Casimir Sep 27 '17 at 14:20
• @Casimir While I concur with your point, I would only note that bounding boxes are regularly exceeded by individual glyphs (take A for example). Why is that? Because the bounding box serves to help alignment with other objects from the same class. So, one argument for not having decorations affect the bounding box is so that two adjacent circle objects align on the baseline, even if one of them has no decoration. – Steven B. Segletes Sep 27 '17 at 14:29
• @Casimir See tex.stackexchange.com/questions/275374/… – Steven B. Segletes Sep 27 '17 at 14:31
• @StevenB.Segletes Interesting and good to know. But I still think it would be nice to have some control over this, e.g. via a class option boundingbox=includeall or something similar. – Casimir Sep 27 '17 at 14:37