# Vertical alignment of tikz circle in equation

I wish to insert a graphic in an equation, and have it horizontally centered.

For example, the circle in the following example should be in the center of the brackets, not sitting halfway above them.

\documentclass{article}
\usepackage{tikz}
\begin{document}
$$A + B \Big \langle \tikz \draw (0,0) circle (0.5cm); \Big \rangle$$
\end{document}


How do I achieve this?

I'm aware of the hack here, but find this unsuitable. (It will be impractical for me to hack 50+ such diagrams by hand.)

The standard way to center content in math is \vcenter which alignes a list of vertical material centered to the math axis (the invisible line the minus sign, the equal sign, fractions etc. are aligned):

\documentclass{article}
\usepackage{tikz}
\begin{document}
$$A + B \Big \langle \vcenter{\hbox{\tikz \draw (0,0) circle (0.5cm);}} \Big \rangle$$
\end{document}


Output:

It is still worth mentioning that baseline can help you in an efficient way: by defining a style vertical align that abbreviates the long baseline=... command.

\documentclass{article}
\usepackage{tikz}
\begin{document}
\tikzset{
vertical align/.style={
baseline=-.5*(height("$+$")-depth("$+$"))
}
}
\foreach\size in{\tiny,\footnotesize,\normalsize,\Large,\huge}{
\size
A+B\Big\langle\tikz[vertical align]\draw circle(0.5);\Big\rangle^{ A+B\Big\langle\tikz[vertical align]\draw circle(0.5);\Big\rangle^{ A+B\Big\langle\tikz[vertical align]\draw circle(0.5);\Big\rangle}}
}
\end{document}


What can be done further is that you can apply style globally by saying

\tikzset{
every picture/.style={vertical align}
}


For irrelevant pictures, you can cancel the effect by either grouping or saying [baseline=0pt] or just [baseline]. (Or you can define no vertical align/.style={baseline})

You can also encode the drawing of the circle in a .pic. For example

\tikzset{
cir5/.pic={
\draw circle(0.5);
}
}


Together with the global setting of baseline, the code is now much simpler

    $$A+B\Big\langle\tikz\pic{cir5};\Big\rangle$$


in contrast to

    $$A+B\Big\langle\vcenter{\hbox{\tikz\draw circle(0.5);}}\Big\rangle$$


Of course one can do something like \def\vcentertikz#1{\vcenter{\hbox{\tikz{#1}}}}, just like one can do \def\tikzvcenterpic#1{\tikz[vcenter]{\pic{#1}}}. So as long as one does not need tricky baseline setting (such as baseline=(node.anchor)), both methods are interchangeable.

The following is the full code.

\documentclass{article}
\usepackage{tikz}
\begin{document}
\tikzset{
vertical align/.style={
baseline=-.5*(height("$+$")-depth("$+$"))
}
}
\foreach\size in{\tiny,\footnotesize,\normalsize,\Large,\huge}{
\size
A+B\Big\langle\tikz[vertical align]\draw circle(0.5);\Big\rangle^{ A+B\Big\langle\tikz[vertical align]\draw circle(0.5);\Big\rangle^{ A+B\Big\langle\tikz[vertical align]\draw circle(0.5);\Big\rangle}}
}

\clearpage

\tikzset{
every picture/.style={vertical align}
}
\foreach\size in{\tiny,\footnotesize,\normalsize,\Large,\huge}{
\size
$$A+B\Big\langle\tikz\draw circle(0.5);\Big\rangle^{ A+B\Big\langle\tikz\draw circle(0.5);\Big\rangle^{ A+B\Big\langle\tikz\draw circle(0.5);\Big\rangle}}$$
}

\clearpage

\tikzset{
cir5/.pic={
\draw circle(0.5);
}
}
\foreach\size in{\tiny,\footnotesize,\normalsize,\Large,\huge}{
\size
$$A+B\Big\langle\tikz\pic{cir5};\Big\rangle ^{A+B\Big\langle\tikz\pic{cir5};\Big\rangle ^{A+B\Big\langle\tikz\pic{cir5};\Big\rangle}}$$
}

\clearpage

\foreach\size in{\tiny,\footnotesize,\normalsize,\Large,\huge}{
\size
$$A + B \Big \langle \vcenter{\hbox{\tikz \draw (0,0) circle (0.5cm);}} \Big \rangle^{ A + B \Big \langle \vcenter{\hbox{\tikz \draw (0,0) circle (0.5cm);}} \Big \rangle^{ A + B \Big \langle \vcenter{\hbox{\tikz \draw (0,0) circle (0.5cm);}} \Big \rangle}}$$
}

\end{document}