[Tex/LaTex] Vertical alignment of text between images

vertical alignment

I need to center (vertically) some text between two images of different size in Latex and would like to ask whether there is a simple way (similar to the \centering for horizontal alignment) to achieve this? Under "simple" I mean without minipage's and other onerous methods.

PS The images are inserted via:

\begin{figure}[ht]
\centering
\includegraphics{image1} text1 \includegraphics{image2} text2
\end{figure}

and currently all of them are aligned so to touch the bottom of the row:

enter image description here

Best Answer

enter image description here

Just to summarize what was mentioned in the comments above and provide some comparison and comments on accuracy and simplicity. Additionally, I suggest a fourth approach with \parboxes with high accuracy. All the approaches below use only LaTeX macros, but other primitive methods can be used.

\documentclass{article}
\setlength{\parindent}{0in}
\usepackage{calc}
\usepackage[export]{adjustbox}
\begin{document}

\newcommand{\picA}{\includegraphics[height=1.25in,width=1.7in]{example-image-A.pdf}}
\newcommand{\picB}{\includegraphics[height=.5in,width=1in]{example-image-B.pdf}}

\parbox{\widthof{\picA}}{\picA} + another one
\parbox{\widthof{\picB}}{\picB} =

\bigskip

\begin{tabular}{@{}c@{}}\picA\end{tabular} + another one
\begin{tabular}{@{}c@{}}\picB\end{tabular} =

\bigskip

\raisebox{-.5\height}{\picA} + another one
\raisebox{-.5\height}{\picB} =

\bigskip

\includegraphics[valign=m,width=1.7in]{example-image-A.pdf} + another one
\includegraphics[valign=m,width=1in]{example-image-B.pdf} =

\end{document}

Method 1

I suggested \parboxes because they are naturally vertically aligned, so this property can be used for vertically aligning images. The accuracy here is the highest of all other methods (observe the alignment of the horizontal bar of + with the image center line), but one must explicitly provide a width argument to the \parbox macro. Fortunately, we have the calc package, which can provide that length to \parbox seamlessly. In this case, \widthof command is used.

Method 2

In the second method, two tabulars are used. This seems a simple method, but unfortunately, the alignment is not perfect out of the box. We observe that the images are a bit higher than the + and the = signs.

Method 3

The third method uses the \raisebox macro from graphicx package (note that adjustbox loads graphicx). This also seems a simple method, but unfortunately, the alignment is again not perfect out of the box. We observe that the images are a bit lower than the + and the = signs.

Method 4

The last method uses the valign=m command from adjustbox package to center the images vertically. The accuracy here is improved (better than the above two methods), but using valign=m in conjunction with height=<length> scales the images unexpectedly.