0

I am trying to center vertically the text in table cells but I can't make it work with my current table. This is the setup I have so far using the m argument, which I attempted by looking here.

\documentclass[10pt,a4paper]{article}

\usepackage[usenames,dvipsnames,svgnames,table]{xcolor} % use color
\usepackage{booktabs} % commands for table rules
\usepackage{tabularx}
\usepackage{lipsum}

\newcommand{\scell}[1]{\cellcolor{black!25} \bfseries #1 }
\newcommand{\slcell}[1]{\cellcolor{black!25} #1 }


\begin{document}

\begin{tabular}{|>{\arraybackslash}m{1.8cm}|>{\centering\arraybackslash}m{3.5cm}|>{\centering\arraybackslash}m{2.8cm}|>{\centering\arraybackslash}m{2.8cm}|>{\centering\arraybackslash}m{2.8cm}|}
\hline 
& \textbf{Given names}  &  \multicolumn{3}{c|}{\textbf{\centering Testing}} \tabularnewline
\hline
\multicolumn{5}{|l|}{  \scell{Category 1}}   \tabularnewline
\hline 
 & Person 1  & \multicolumn{3}{p{9cm}|}{\lipsum[1] }  \tabularnewline
\hline 
\end{tabular}


\end{document}

This gives me the following result:

enter image description here

1

Use \multicolumn3{m{9cm}}{…} instead of p{9cm}. As your table is too wide to fit the margins, I took the opportunity to change it using tabularx. Also note the usenames option for xcolor is obsolete: it's the default now.

\documentclass[10pt,a4paper]{article}
\usepackage[showframe]{geometry} %
\usepackage[dvipsnames,svgnames,table]{xcolor} % use color
\usepackage{booktabs} % commands for table rules
\usepackage{tabularx}
\usepackage{lipsum}

\newcommand{\scell}[1]{\cellcolor{black!25} \bfseries #1 }
\newcommand{\slcell}[1]{\cellcolor{black!25} #1 }


\begin{document}

\noindent
\begin{tabularx}{\linewidth}{|>{\arraybackslash}m{1.5cm}|>{\centering\arraybackslash}X|>{\centering\arraybackslash}m{2.8cm}|>{\centering\arraybackslash}m{2.8cm}|>{\centering\arraybackslash}m{2.8cm}|}
\hline
& \textbf{Given names} & \multicolumn{3}{c|}{\textbf{\centering Testing}} \tabularnewline
\hline
\multicolumn{5}{|l|}{ \scell{Category 1}} \tabularnewline
\hline
 & Person 1 & \multicolumn{3}{m{9cm}|}{\lipsum[1] } \tabularnewline
\hline
\end{tabularx}

\end{document} 

enter image description here

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.