5

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.

enter image description here

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?

6
\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}

enter image description here

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.

2

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)}

enter image description here

\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}

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.