4

When creating a TikZ snippet inside a figure caption, the snippet is never really aligned with the surrounding text. For example,

\documentclass{article}

\usepackage{tikz}

\begin{document}

\begin{figure}
\caption{%
  (\protect\tikz \protect\node [circle,draw=black,minimum width=1em]{};)
  }
\end{figure}

\end{document}

produces

enter image description here

I suppose it all looks alright if the circle sits comfortably on the base line. How to get it there?

2 Answers 2

7

Give the node some (invisible) content and a name and use the base (or any other desired) anchor for baseline; you can also pass explicit lengths to baseline for finer control. The following example shows both options (I also set inner sep=0pt for the second example):

\documentclass{article}
\usepackage{tikz}

\begin{document}

\begin{figure}
\caption{%
  (\protect\tikz[baseline=(circ.base)] \protect\node[circle,draw=black,minimum width=1em] (circ) {\protect\phantom{a}};)
    (\protect\tikz[baseline=-0.7ex] \protect\node[circle,draw=black,inner sep=0pt,text width=1em] (circ) {\protect\phantom{a}};)}
\end{figure}

\end{document}

The result:

enter image description here

2

The math mode command \vcenter centers its material around the math axis:

\documentclass{article}

\usepackage{tikz}

\begin{document}
\listoffigures

\begin{figure}
\caption{%
  (%
    $\vcenter{\hbox{%
      \protect\tikz \protect\node [circle,draw=black,minimum width=1em]{};%
    }}$%
  )%
}
\end{figure}
\end{document}

Result

The additional \hbox prevents, that \tikz starts a new paragraph inside \vcenter with a full line width. Both \vcenter and \hbox are robust and do not need \protect.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .