3

I am using inline tikz calls to create annotations in my documents.

I am using the (below defined) \Curve macro to annotate graph plots (e.g. created with pgfplots) and \Curvee macro for more general drawings that could be bent, hence the use of to path instead of -- path. I manage to align the contents of the \tikz call using the baseline option and some current bounding box properties.

However, when using bend ... or in=...,out=... options to the to path, empty space is left inside the bounding box. When -stealth arrows are used there are also some discrepancies in the bounding box. Note that a -Stealth arrow updates the bounding box very well.

In this post it is said that the arrrows for the arrows.meta library should update the bounding box (while previous arrows could not).

So I have two questions actually :

  • Why do the stealth arrows no update the bounding box correctly ? (I thought they were just -Stealth arrows with some default settings, but maybe not)
  • Why is there an empty space in the bounding box of to path wiht in=...,out=... options ? (probably because of some construction nodes but if someone can explain...)
\documentclass{article}
\usepackage{tikz}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{times}
\usepackage{mathptmx}
\usetikzlibrary{arrows.meta,calc}
\usepackage{xparse}

\DeclareDocumentCommand\Curve{ m O{} }{%
    (%
    \tikz[baseline=(ref.base)] {%
        \draw[#1] plot coordinates {(0,0)} -- plot[#2] coordinates {(2mm,0)} -- plot coordinates {(4mm,0)};%
        \draw[] (current bounding box.south west) rectangle (current bounding box.north east);
        \coordinate[yshift=-\the\dimexpr\fontdimen22\textfont2] (ref) at (current bounding box.center);
    }%
    )%
}
\DeclareDocumentCommand\Curvee{ m O{} }{%
    (%
    \tikz[baseline=(ref.base)] {%
        \draw[#1] (0,0) to[#2] (4mm,0mm);%
        \draw[] (current bounding box.south west) rectangle (current bounding box.north east);
        \coordinate[yshift=-\the\dimexpr\fontdimen22\textfont2] (ref) at (current bounding box.center);
    }%
    )%
}

\begin{document}
$1$
\Curve{red,-stealth}
\Curve{red,->}
\Curvee{red,-stealth,bend left}
\Curvee{red,->,bend left}
\Curvee{red,-stealth}[out=-60,in=150]
\Curvee{red,-Stealth}[out=-60,in=150]
\end{document}

enter image description here

3
  • 3
    The bounding box of spline curves contains the control points. Don't use \DeclareDocumentCommand, but prefer \NewDocumentCommand, so you'll be warned if you're trying to define an existing command. – egreg Sep 13 '19 at 8:48
  • @egreg, thanks for the tip on NewDocumentCommand, in general my personal macros are in french so overriding is not that common ^^. Regarding the controls points, that's what I thought at first, but the bend left actually defines in=...,out=... settings and does not leave so much space. Any idea regarding the stealth arrows ? – BambOo Sep 13 '19 at 9:11
  • @egreg, Ok my comment about bend left is idiotic, for sure with a two-sloped curve, the control points will be farther from the center. Sorry about that – BambOo Sep 13 '19 at 11:01
4

The question of getting a tight bounding box for Bezier curves is a repeating one, and, as egreg mentions, in TikZ the bounding box of a Bezier curve is taken to be the minimal box that contains its control points. In general, this yields a too generous bounding box. If you download the experimental librarytikzlibrarybbox.code.tex from here (with the explanations being available here), you can solve the problem for the arrow heads from arrows.meta.

\documentclass{article}
\usepackage{tikz}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{times}
\usepackage{mathptmx}
\usetikzlibrary{arrows.meta,calc,bending,bbox}
\newcommand\Curvee[2][]{%
    (%
    \tikz[baseline=(ref.base)] {%
     \begin{scope}[bezier bounding box]
        \draw[#2] (0,0) to[#1] (4mm,0mm);%
        \draw[] (current bounding box.south west) rectangle (current bounding box.north east);
        \coordinate[yshift=-\the\dimexpr\fontdimen22\textfont2] (ref) at (current bounding box.center);
      \end{scope}   
    }%
    )%
}

\begin{document}
$1$
\Curvee[bend left]{red,-Stealth}
\Curvee[out=-60,in=150]{red,-Stealth}
\Curvee[out=-60,in=150]{red,-Stealth}

$2$
\Curvee[bend left]{red,-{Stealth[bend]}}
\Curvee[out=-60,in=150]{red,-{Stealth[bend]}}
\Curvee[out=-60,in=150]{red,-{Stealth[bend]}}
\end{document}

enter image description here

I also loaded the bending library and bent the last three arrows. Notice that bending improves the arrow heads already when you only load the library, i.e. even if you do not add bend to the corresponding arrow options.

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.