Search code examples
graphicslatexvertical-alignmentxelatex

Vertically center text and image in two lines


I need to place a text of two lines next to a centered image.

I have already tried the code provided in https://tex.stackexchange.com/questions/433/vertically-center-text-and-image-in-one-line/17101, which works great for a single line, but cannot get it to work for for than one.

\newcommand{\vcenteredinclude}[1]{\begingroup
\setbox0=\hbox{\includegraphics[scale=0.3]{#1}}%
\parbox{\wd0}{\box0}\endgroup}

\par{\hspace{3cm}\LARGE \centering
    {text}{\\more text under text} \hspace{2cm}\smallskip       \vcenteredinclude{myimage}\par}

can you please help?


Solution

  • The simpler is to use an array IMHO. The array package extends tabular by adding several extra column specifier and one, m is like p (paragraph), but the paragraph is centered in the cell. So, just put you text in a 'm' paragraph and the image in another. The resulting code is straightforward.

    \documentclass{article}
    \usepackage{graphicx}
    \usepackage{array}
    \begin{document}
    \begin{tabular}{m{5cm}m{5cm}}
     mona lisa mona lisa mona lisa mona lisa mona lisa mona lisa 
       &\includegraphics[width=\linewidth]{monalisa}
    \end{tabular}
    \end{document}
    

    enter image description here

    One can adjust the width between the image and the text with

    \setlength{\tabcolsep}{2cm}