2

I am drawing an arrow with text above it

\documentclass[tikz]{standalone} 
\usetikzlibrary{decorations.text}
\begin{document}
\begin{tikzpicture}
\draw[<-, thick, postaction={decorate, decoration={text along path,text align=center, raise=.7em, text={Process}}}]
        (0, 0) to [bend left=60] (5, 0);
\end{tikzpicture}
\end{document}

The result cuts off the top of the text of the label. enter image description here

How can I fix the bounding box of the tikzpicture so that it adjusts itself the text of the label? Can I get the decorations to extend the bounding box, the way arrows.meta does for arrows?


I would like the bounding box of the tikzpicture to adjust automatically to the contents of the picture, rather than have to fine tune a fixed value.

If I put the text in its own node, it doesn't get cut off, but then it doesn't follow the path of the arrow.

Of course, I can not raise the text, but then it is too close to the arrow.


The accepted answer here has nothing to do with my problem, since the arrows.meta package doesn't change the bounding box for decorations. The other answers to that question suggest adding margins, but I do not want to have to fine tune the margin parameter (and then have to change it again, if I move the arrow decoration).

  • No problem here. Maybe you have some other command to clip the images. – Sigur Feb 18 '20 at 14:59
  • 1
    Without a complete example, it's difficult to answer. The answer, I think, is that you made a mistake before because your code compiles perfectly. – Alain Matthes Feb 18 '20 at 15:00
  • It compiles, but the top is cut off in the output – usernumber Feb 18 '20 at 15:01
  • no your code is correct. You need to give a complete example with the document class etc . – Alain Matthes Feb 18 '20 at 15:03
  • 2
    If we try OP's code with standalone class, we get the issue about which s/he is talking. Try this `\documentclass[tikz]{standalone} \usetikzlibrary{decorations.text}

    \begin{document} \begin{tikzpicture} \draw[<-, thick, postaction={decorate, decoration={text along path,text align=center, raise=.7em, text={Process}}}] (0, 0) to [bend left=60] (5, 0); \end{tikzpicture} \end{document}`

    – Niranjan Feb 18 '20 at 15:04
  • 6
  • The arrow endpoints look nicer with \usetikzlibrary{arrows.meta}, but the label is still cut off. And with margin=1cm, I have to change the margin value if I change the label. – usernumber Feb 18 '20 at 15:17
  • Technically, standalone is cutting off the top, which extends beyond the bounding box. The quick fix is to add a [border=10pt] or so to standalone. Another solution is t add an invisible point above the (current bounding box). – John Kormylo Feb 18 '20 at 15:59
  • 1
    It is a known bug: https://tex.stackexchange.com/q/497684. –  Feb 18 '20 at 16:00
  • You can cheat: \documentclass[tikz]{standalone} \usetikzlibrary{decorations.text} \begin{document} \begin{tikzpicture} \draw[<-, thick, postaction={decorate, decoration={text along path, text align=center, raise=.7em, text={Process}}}] (0, 0) to [bend left=60] node[above={0.7em-2pt}] (cheat) {\phantom{Process}} (5, 0); \end{tikzpicture} \end{document}. –  Feb 18 '20 at 16:25
  • @Schrödinger'scat I have no problem with standalone 2018/03/26 v1.3a and the initial code. I compile with lualatex but it's correct with pdflatex too – Alain Matthes Feb 18 '20 at 19:32
  • 1
    @AlainMatthes I do reproduce the issue. More precisely, if I compile the example, the text is barely in (but not cut as badly as in the OP's screen shot). If I use text={|\Huge|Process}, then it gets cut more badly. The fact that it is is originally partly visible is IMHO an accident because the bounding box gets overestimated, a well known effect for Bezier curves that you wrote a nice answer for. ;-) –  Feb 18 '20 at 19:39
  • @Schrödinger'scat ok now I see !! But I know another bug ! now I'm old and I'm forgetting what I've been studying... – Alain Matthes Feb 18 '20 at 19:51
  • @AlainMatthes For the Bézier curve problem there is now the bbox library that is described in section 46 Bounding Boxes for Bézier Curves of pgfmanual v3.1.5. I always plan to make it more stable but somehow I never have more than 20 minutes time so I keep postponing. –  Feb 18 '20 at 19:59
  • 1
    @usernumber By default, the standalone class cuts the image according to its size plus a border of 0pt. This border can be enlarged. There is no other way to fix this in the manual, except to permanently change this border by modifying the standalone.cfg file in your local texmf so that the border added with e.g. border={0pt 1.5pt} is permanently changed.Thus, @Kate's solution is in my opinion the only valid one here. – AndréC Feb 20 '20 at 10:30

2 Answers2

1

The bounding box is not calculated correctly. One can proof this by drawing the bounding box using \draw[red] (current bounding box.north west) rectangle (current bounding box.south east);

enter image description here

Quick hack is to add a margin to standalone class.

\documentclass[tikz,margin=1cm]{standalone} 
\usetikzlibrary{decorations.text}
\begin{document}
\begin{tikzpicture}
\draw[<-, thick, postaction={decorate, decoration={text along path,text align=center, raise=.7em, text={Process}}}]
        (0, 0) to [bend left=60] (5, 0);
\end{tikzpicture}
\end{document}
Kate
  • 382
0

By making the text follow a path different from that of the arrow, the text follows a bend and is not cut off by the bounding box

\begin{tikzpicture}
\pgfmathsetmacro{\xa}{0}
\pgfmathsetmacro{\xb}{5}
\pgfmathsetmacro{\y}{0}
\pgfmathsetmacro{\m}{.2}

\draw[<-, thick]
        (\xa, \y) to [bend left=60] (\xb, \y);

\path [decorate,decoration={text along path, text align=center, text={Process}}] (\xa, \y + \m) to [bend left=60] (\xb, \y + \m);

\end{tikzpicture}