# How to specify tikzpicture vertical position in the middle of text?

I would like to put a tikzpicture in the middle of a text line, but I can't find how to specify vertical positionning. Explications :

\documentclass{article}
\usepackage[english]{babel}
\usepackage{tikz}

\begin{document}
Lorem ipsum dolor sit amet, consectetur adipiscing elit
\begin{tikzpicture}
\draw (2.25, 2) -- (2,0);
\draw (.7, 0) -- (4,0) -- (2.25, 2) node[right] {$A_i$} -- (.7,0);
\draw (3,0) -- (2.125, 1) node[right] {$A_j$} -- (1.4,0);
\draw (1.05, 0) node[below] {$v$} (2,0) node[below] {$w$} (3.5, 0) node[below] {$x$} (4.5, 0);
\end{tikzpicture}

\end{document}


gives me something like

but I would like to get something like

I know vertical positioning options exist for tabular and array (\begin{array}[b]{rcl} for a bottom alignment for exemple), but I can't find something similar for tikzpictures.

Here's another approach that works if you want to put more text on the same line. It puts the figure in a box and then lowers the box by half its height.

\documentclass{article}
\usepackage[english]{babel}
\usepackage{tikz}

\newbox\mybox
\def\centerfigure#1{%
\setbox\mybox\hbox{#1}%
\raisebox{-0.5\dimexpr\ht\mybox+\dp\mybox}{\copy\mybox}%
}
\begin{document}
Lorem ipsum dolor sit amet,
\centerfigure{\begin{tikzpicture}
\draw (2.25, 2) -- (2,0);
\draw (.7, 0) -- (4,0) -- (2.25, 2) node[right] {$A_i$} -- (.7,0);
\draw (3,0) -- (2.125, 1) node[right] {$A_j$} -- (1.4,0);
\draw (1.05, 0) node[below] {$v$} (2,0) node[below] {$w$} (3.5, 0) node[below] {$x$} (4.5, 0);
\end{tikzpicture}} more text
\end{document}


Coincidentally, I just solved a similar problem. Applied to your example, that works out to be this:

\documentclass{article}
\usepackage{tikz}

\begin{document}
Lorem ipsum dolor sit amet,%
\begin{tikzpicture}[baseline=(AA.base)]%
\draw (2.25, 2) -- (2,0);
\draw (.7, 0) -- (4,0) -- (2.25, 2) node[right] {$A_i$} -- (.7,0);
\draw (3,0) -- (2.125, 1) node[right](AA) {$A_j$} -- (1.4,0);
\draw (1.05, 0) node[below] {$v$} (2,0) node[below] {$w$} (3.5, 0) node[below] {$x$};
\end{tikzpicture}%
more text
\end{document}


True, that this works happens to be due to the nature of the figure. Admittedly, Hood Chatham's solution is more general.

Changing [baseline=(AA.base)] to [baseline=(AA.south)] produces this:

I think using math mode and \vcenter is the way to go for vertically centering stuff on the current text line:

\documentclass{article}
\usepackage[english]{babel}
\usepackage{tikz}

\begin{document}
Lorem ipsum dolor sit amet, consectetur adipiscing elit
$\vcenter{\begin{tikzpicture} \draw (2.25, 2) -- (2,0); \draw (.7, 0) -- (4,0) -- (2.25, 2) node[right] {$A_i$} -- (.7,0); \draw (3,0) -- (2.125, 1) node[right] {$A_j$} -- (1.4,0); \draw (1.05, 0) node[below] {$v$} (2,0) node[below] {$w$} (3.5, 0) node[below] {$x$} (4.5, 0); \end{tikzpicture}}$

\end{document}

• Thanks for that answer, but the \vcenter environment ends the line, so I can't continue the line with some text. – Nathaniel Oct 21 '17 at 14:22
• That's annoying. I'll see if I can fix that... – Hood Chatham Oct 21 '17 at 14:25
• See my second answer. – Hood Chatham Oct 21 '17 at 14:32