Search code examples
latextabulartext-alignmentbeamer

How to center text vertically in tabular cells using Beamer?


The text is bottom-aligned in tabular cells using the Beamer class. I've tried solutions from answers to previous questions, but none works for me. They include using multicolumn, multirow, parbox, minipage, a nested tabular environment, etc.

Here's a minimal working example:

\documentclass{beamer}

\usepackage{diagbox}
\usepackage{array}

\begin{document}
   
  \begin{frame}
     \begin{center}
       \vspace{\baselineskip}
       \begin{table}
       \begin{tabular}{|m{3cm}|c|c|}
          \hline
          \diagbox[width=3cm]{Text}{Text} & Text & Text\\
          \hline
          Text & \includegraphics[width=3cm]{example-image-a}  & \includegraphics[width=3cm]{example-image-a} \\
          \hline
          Text & \includegraphics[width=3cm]{example-image-a}  & \includegraphics[width=3cm]{example-image-a} \\
          \hline
       \end{tabular}
       \end{table}
     \end{center}
  \end{frame}

\end{document}

Here's this code on Overleaf:

https://www.overleaf.com/read/xyhxppcggcxw#b44e1e

Here's a copy you can edit:

https://www.overleaf.com/2546442868dkwtxcdnvryn#708448


Solution

  • You could use the valign=... option from adjustbox to chang ethe vertical alignment of your images:

    \documentclass{beamer}
    
    \usepackage{diagbox}
    \usepackage{array}
    \usepackage[export]{adjustbox}
    
    \begin{document}
       
      \begin{frame}
           \begin{table}
           \begin{tabular}{|m{3cm}|c|c|}
              \hline
              \diagbox[width=3cm]{Text}{Text} & Text & Text\\
              \hline
              Text & \includegraphics[width=3cm,valign=c]{example-image-a}  & \includegraphics[width=3cm,valign=c]{example-image-a} \\
              \hline
              Text & \includegraphics[width=3cm,valign=c]{example-image-a}  & \includegraphics[width=3cm,valign=c]{example-image-a} \\
              \hline
           \end{tabular}
           \end{table}
      \end{frame}
    
    \end{document}
    

    enter image description here