4

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}

enter image description here

1

2 Answers 2

4

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}

enter image description here

2
  • @Mark Wibrow Note that this also increases the arrow head size quite a bit.
    – Casimir
    Sep 27, 2017 at 15:22
  • 1
    @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]}. Sep 27, 2017 at 15:53
1

Pass the margin option within the class:

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

enter image description here

4
  • 2
    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, 2017 at 14:20
  • 2
    @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. Sep 27, 2017 at 14:29
  • 1
    @Casimir See tex.stackexchange.com/questions/275374/… Sep 27, 2017 at 14:31
  • 1
    @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, 2017 at 14:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.