1

I am preparing a presentation with beamer and I have to make a table with some multi-line cells. So I am using the tabularx environment and my code is the following:

\documentclass{beamer}

\usepackage{tabularx}
\usepackage{graphicx}

\begin{document}
\begin{frame}{Title}

\newcommand{\tick}{%
\includegraphics[scale=0.2]{img/green-tick}%
}

\begingroup
\renewcommand*{\arraystretch}{2.0}
\begin{center}
\begin{tabularx}{0.95\textwidth}{|X|X|X|X|X|}

\hline
\centering\textbf{Column 1} &
\centering \textbf{Column 2} &
\centering \textbf{Column 3} &
\centering \textbf{Column 4} &
\textbf{Column 5}\\

\hline
Row 1\newline blah &
\tick &
\tick &
\tick & \\

\hline
Row 2 &
\tick &
&
\tick &
\tick\\

\hline
Row 3\newline blah &
\tick &
\tick &
&
\tick\\

\hline
Row 4 & 
&
\tick &
\tick &
\tick\\

\hline
Row 5 &
\tick &
\tick &
\tick &
\tick\\
\hline
\end{tabularx}
\end{center}
\endgroup
\end{frame}
\end{document}

The result is

enter image description here

What I would like to do is simply to center (both horizontally and vertically) the images in their respective cells.

4

You can set the X column type to use m instead of the default p, and vertically center the image with a nested tabular.

\documentclass{beamer}

\usepackage{tabularx}
\usepackage{graphicx}

\newcommand{\tick}{%
  %https://openclipart.org/image/2400px/svg_to_png/167549/Kliponious-green-tick.png
  \begin{tabular}{@{}c@{}}
  \includegraphics[width=.5cm]{Kliponious-green-tick.png}
  \end{tabular}%
}
\newcommand{\middlexcolumn}{%
  \renewcommand{\tabularxcolumn}[1]{m{##1}}%
}

\begin{document}
\begin{frame}{Title}

\begin{center}
\renewcommand*{\arraystretch}{2.0}
\middlexcolumn
\begin{tabularx}{0.95\textwidth}{%
  | *{4}{>{\centering}X|}
  >{\centering\arraybackslash}X|
}
\hline
\textbf{Column 1} &
\textbf{Column 2} &
\textbf{Column 3} &
\textbf{Column 4} &
\textbf{Column 5}\\

\hline
Row 1\\ blah &
\tick &
\tick &
\tick & \\

\hline
Row 2 &
\tick &
&
\tick &
\tick\\

\hline
Row 3\newline blah &
\tick &
\tick &
&
\tick\\

\hline
Row 4 & 
&
\tick &
\tick &
\tick\\

\hline
Row 5 &
\tick &
\tick &
\tick &
\tick\\
\hline
\end{tabularx}
\end{center}

\end{frame}
\end{document}

enter image description here

  • Works perfectly, and I admit I would have never guessed how to do that! – minomic Aug 22 '16 at 6:20

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.