3

Consider this example:

\documentclass{standalone}
%\documentclass[margin=1cm]{standalone}                                                                                                                                                                     

\usepackage{tikz}

\usetikzlibrary{decorations.text}
\begin{document}

\begin{tikzpicture}

\draw (0,0) ellipse (2cm and 1 cm);
\path[
   postaction={decorate},
     decoration={
       text along path,
       raise=-0.3cm,
       text={some text}
  }
] (0,0) ellipse (2cm and 1cm);
\end{tikzpicture}

\end{document}

In the output:

enter image description here

standalone only respects the ellipse but disregards the tikz text decorations.

To correct I need to manually supply [margin=1cm] for standalone.

Why doesn't standalone take a holistic approach when defining pdf borders?

5
  • 2
    Please note that this by far not the only situation in which the bounding box is not accurate. The answer to "Why is standalone ignoring tikz decorations.text?" is that "TikZ does not always compute the bounding box perfectly.". This is something that has been discussed in many threads. Most likely the algorithm that computes the bounding box is not prepared for negative values raise=-0.3cm,.
    – user121799
    Jun 27 '19 at 16:44
  • @marmot added with something similar to overlay perhaps?
    – daleif
    Jun 27 '19 at 16:51
  • @daleif overlay does the opposite: it takes things out of the bounding box computation.
    – user121799
    Jun 27 '19 at 16:52
  • @marmot that is what I mean, it clearly looks af if it was never considered for the bbox calc
    – daleif
    Jun 27 '19 at 16:53
  • 2
    @daleif I don't know. To me it seems simply that this does not create a path and thus does not alter the bounding box. (I vaguely remember having seen this somewhere before.)
    – user121799
    Jun 27 '19 at 16:59
4

There is a long series of related posts such as this one and this one. The upshot is that TikZ uses some approximations to determine the bounding box. For curves, it considers the control points, and not the actual points the curve runs through. This has the advantage that his rather fast, and the disadvantage that the bounding box does not fit perfectly. In the case at hand, it seems that the texts are no paths and thus do not alter the bounding box.

So all I can offer is to fix the issue by hand by adding an arc that (approximately) runs along the outer side of the path.

\documentclass{standalone}
%\documentclass[margin=1cm]{standalone}                                                                                                                                                                     

\usepackage{tikz}

\usetikzlibrary{decorations.text}
\begin{document}

\begin{tikzpicture}

\draw (0,0) ellipse (2cm and 1 cm);
\path[
   postaction={decorate},
     decoration={
       text along path,
       raise=-0.3cm,
       text={some text}
  }
] (0,0) ellipse (2cm and 1cm);
\path (2.4,0) arc(0:60:2cm and 1.4cm);
\end{tikzpicture}
\end{document}

enter image description here

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.