# Aligning tikz picture in equation

I am trying to write an equation involving tikz picture and math symbols. Here is the MWE:

\documentclass{article}
\usepackage{tikz}
\begin{document}
$T=\begin{tikzpicture}[line cap=round,line join=round,x=1cm,y=1cm] \draw [line width=1pt] (-6,1)-- (-3,1); \draw [line width=1pt] (-5,2)-- (-5,0); \draw [line width=1pt] (-4,2)-- (-4,0); \end{tikzpicture}$
\end{document}


It produces something like this. But I want the picture to be placed in such a way that $T=$ thing is aligned with the horizontal line of the picture. Any idea how to do it?

## 2 Answers

\documentclass{article}
\usepackage{tikz}
\begin{document}
You could just use \verb|\vcenter{\hbox{\begin{tikzpicture}|$\cdots$\verb|\end{tikzpicture}}}|
$T=\vcenter{\hbox{\begin{tikzpicture}[line cap=round,line join=round,x=1cm,y=1cm] \draw [line width=1pt] (-6,1)-- (-3,1); \draw [line width=1pt] (-5,2)-- (-5,0); \draw [line width=1pt] (-4,2)-- (-4,0); \end{tikzpicture}}}$
or, alternatively, adjust the \verb|baseline|
$T=\begin{tikzpicture}[line cap=round,line join=round,x=1cm,y=1cm,baseline={1cm-0.5*height("=")}] \draw [line width=1pt] (-6,1)-- (-3,1); \draw [line width=1pt] (-5,2)-- (-5,0); \draw [line width=1pt] (-4,2)-- (-4,0); \end{tikzpicture}$
\end{document} Note that if the tikzpicture has nodes, you can set the baseline of the tikzpicture to, say, the baseline of a node, baseline={(X.base)}, where X is the name of the node.

Tikz allows to align the base line on a coordinate. See p 127 of the 3.1.3 manual.

here, it is enough to align it on the line \draw[line width=1pt] (-6,1)-- (-3,1);

baseline={(0, 1cm)}


But, as explained by Heiko Oberdiek, the equals sign is centered around the math axis. It is therefore sufficient to subtract this height from the baseline coordinate.

\pgfmathsetmacro\MathAxis{height("$\vcenter{}$")}
baseline={(0, 1cm-\MathAxis pt)} \documentclass{article}
\usepackage{tikz}
\begin{document}

% macro from Heiko Oberdiek solution https://tex.stackexchange.com/a/355693/138900
\pgfmathsetmacro\MathAxis{height("$\vcenter{}$")}
$T=\begin{tikzpicture}[baseline={(0, 1cm-\MathAxis pt)},line cap=round,line join=round,x=1cm,y=1cm] \draw [line width=1pt] (-6,1)-- (-3,1); \draw [line width=1pt] (-5,2)-- (-5,0); \draw [line width=1pt] (-4,2)-- (-4,0); \end{tikzpicture}$
\end{document}