3

This is a direct follow-up to my question Align itemize bullet within tikz environment. I basically have the same question as then, except that this time, I need to align the itemize bullet with an arrow that is drawn between an above and a below node.

By default, the alignment shows up like this:

\documentclass{article}
\usepackage{tikz}
\begin{document}

\begin{itemize}
    \item
        \begin{tikzpicture}[baseline = default]
            \draw [very thick, ->] (0,0) -- (2,0);
            \node[above] at (1,0) {Text above};
            \node[below] at (1,0) {Text below};
        \end{tikzpicture}
\end{itemize}

\end{document}

enter image description here

Following Andrew Swann's answer, I tried to name my drawing (e.g. (myarrow)) and set the baseline to its base, but this doesn't work - I can presumably only name nodes. So I create an empty node that I name:

\documentclass{article}
\usepackage{tikz}
\begin{document}

\begin{itemize}
    \item
        \begin{tikzpicture}[baseline = (A.base)]
            \draw [very thick, ->] (0,0) -- (2,0);
            \node at (0,0) (A) {};
            \node[above] at (1,0) {Text above};
            \node[below] at (1,0) {Text below};
        \end{tikzpicture}
\end{itemize}

\end{document}

enter image description here

But the bullet is still vertically misaligned with the arrow. What do I need to do in order to set the baseline of the tikzpicture environment to the base of the arrow?


EDIT

It was suggested in a comment to Align itemize bullet within tikz environment to use -.5ex as the baseline, and Kevin C's answer here suggests the same approach. While this is a good approximation to a perfect vertical alignment, it doesn't quite get there. As indicated already in my comment to Align itemize bullet within tikz environment, how good the approximation is will depend on the font used (and this means that one would need to manually tweak the exact baseline on a document per document basis), and in this case, one can also see that the alignment is slightly off. Cf. the MWE below (I've added the red midline manually later).

\documentclass{article}
\usepackage{tikz}
\begin{document}

\begin{itemize}
    \item
        \begin{tikzpicture}[baseline = -.5ex]
            \draw [very thick, ->] (0,0) -- (2,0);
            \node[above] at (1,0) {Text above};
            \node[below] at (1,0) {Text below};
        \end{tikzpicture}
\end{itemize}

\end{document}

enter image description here

Sverre
  • 20,729

1 Answers1

2

My understanding is that item bullets are usually .5ex above the baseline. So if you want your arrow to align exactly as the bullet, just shift everything up vertically by this distance.

Specifically, you can use node (A)'s base as your arrow's starting point, and add .5ex to the above and below nodes.

MWE

\documentclass{article}
\usepackage{tikz}
\begin{document}

\begin{itemize}
    \item %
        \begin{tikzpicture}[baseline = (A.base)]
            \node[inner sep=0pt] at (0,0) (A) {};
            \draw [very thick, ->] ([yshift=.5ex]A.base) -- +(2,0);
            \node[above] at (1,.5ex) {Text above};
            \node[below] at (1,.5ex) {Text below};
        \end{tikzpicture}
\end{itemize}    
\end{document}

Output

enter image description here

Herr K.
  • 17,946
  • 4
  • 61
  • 118
  • 1
    This is a good approximation, but it doesn't quite get there. See the edit to my question. Also, I think it would be an easier approach to just add [baseline = -.5ex] to begin with (see my new MWE). – Sverre Jan 21 '15 at 14:27