4

I am trying to get a text to center vertically within a tabularx. For centered and bottom text it works, but it fails for top text. What am I missing here?

        \begin{tabularx}{\textwidth}{ | X | c | }
            \hline
            \noindent\parbox[t]{\hsize}{\includegraphics[width=5cm]{img/image001}} & top\\
            \hline
            \noindent\parbox[c]{\hsize}{\includegraphics[width=5cm]{img/image001}} & center\\
            \hline
            \noindent\parbox[b]{\hsize}{\includegraphics[width=5cm]{img/image001}} & bottom\\
            \hline
        \end{tabularx}
7

Use valign from adjustbox.

I used also margin=4pt to put some space around the image, and I inverted the column types of your table, I don't think you want an X type for a column where there are only fixed-width images.

\documentclass{article}
\usepackage{tabularx}
\usepackage[export]{adjustbox}
\usepackage{graphicx}

\begin{document}
    \begin{table}\centering
        \begin{tabularx}{\linewidth}{ | c | X | }
            \hline
            \includegraphics[width=5cm, valign=t, margin=4pt]{example-image} & top\\
            \hline
            \includegraphics[width=5cm, valign=c, margin=4pt]{example-image} & center\\
            \hline
            \includegraphics[width=5cm,valign=b, margin=4pt]{example-image} & bottom\\
            \hline
        \end{tabularx}
    \end{table}
\end{document}

enter image description here

Your question may be a duplicate of this one: How to align picture top left in a table?.

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.