7

I don't really understand how I can vertically align the contents of my table. They seem to be all messed up, and I dont know why. Here is a screenshot showing the problem:

enter image description here

And here is the code I am currently using to produce the shown table:

\documentclass{beamer}
\usetheme{Malmoe}
\title{Tex Stack Exchange example}
\subject{Question about vertical centering tables}
\usepackage{array}
\newcolumntype{L}[1]{>{\raggedright\let\newline\\\arraybackslash\hspace{0pt}}m{#1}}
\newcolumntype{C}[1]{>{\centering\let\newline\\\arraybackslash\hspace{0pt}}m{#1}}
\newcolumntype{R}[1]{>{\raggedleft\let\newline\\\arraybackslash\hspace{0pt}}m{#1}}
\setlength\extrarowheight{4pt}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\begin{document}

\begin{frame}{Statistics}{}
\tiny
\begin{center}
\begin{tabular}{| L{1.8cm} | C{0.8cm} | C{0.8cm} | C{0.8cm} | C{0.8cm} | C{0.8cm}| C{0.8cm} | C{0.8cm} |}
\hline
Scenario & Number of events & Number of clusters & Number of healthy clusters & Number of unhealthy clusters & Number of clusters pairs & Number of real cluster pairs & Number of fake cluster pairs \\
\hline
Eff. 76\%  total/module 1/module 4 & 9079 & 36855956 2191062 2917431 & 30235384 495474 1781164 & 6620572 1695588 1136267 & 1347578 513532 92623 & 28242 3407 4090 & 1319336 510125 88533  \\
\hline
Eff. 90\%  total/module 1/module 4 & 8285 & 33935939 1926868 2923980 & 29137926 711464 2148856 & 4798013 1215404 775124 & 1063412 397880 72455 & 26928 3100 4307 & 1036484 394780 68148  \\
\hline
Eff. 100\% total/module 1/module 4 & 9883 & 40379644 214092 366267 & 36443709 119498 3085536 & 3935935 945942 577141 & 896456 320005 59953 & 32121 3484 5551 & 864335 316521 54402  \\
\hline
\end{tabular}
\end{center}
\end{frame}

\end{document}

Can you help me what I should do about the array box centering to fix the "messed up" alignment in the table cells? Thank you in advance!

2
  • Hello Adam, removing the \hspace{0pt} in the line \newcolumntype{C} ... worked to me. Alas, I don't know why. :-(
    – Jan
    Dec 14, 2016 at 13:14
  • 1
    Make the columns with the displaced entries a bit wider. The 8 digit numbers are wider than 0.8cm (there should be overfull hbox warnings in the log file), so TeX breaks the line between \hspace{0pt} and the long number.
    – gernot
    Dec 14, 2016 at 13:16

3 Answers 3

2

I suggest you

  • remove the instructions \let\newline\\ and \hspace{0pt} from the definitions of the L, C, and R column types and

  • set \extrarowheight to a more reasonable value, say,

    \setlength\extrarowheight{2pt}
    

A revised MWE -- I've changed some of the columns widths to allow proper centering of the material.

enter image description here

\documentclass{beamer}
\usetheme{Malmoe}
\usepackage{array}
\newcolumntype{L}[1]{>{\raggedright\arraybackslash}m{#1}}
\newcolumntype{C}[1]{>{\centering\arraybackslash}m{#1}}
\setlength\extrarowheight{2pt} % 4pt seems excessive...

\begin{document}

\begin{frame}{Statistics}{}
\tiny
\centering
\begin{tabular}{| L{1.7cm} | C{0.7cm} | C{0.9cm} | *{5}{C{0.8cm}|} }
\hline
Scenario & Number of events & Number of clusters & Number of healthy clusters & Number of unhealthy clusters & Number of cluster pairs & Number of real cluster pairs & Number of fake cluster pairs \\
\hline
Eff.\ 76\%~total\slash module~1\slash module~4 & 9079 & 36855956 2191062 2917431 & 30235384 495474 1781164 & 6620572 1695588 1136267 & 1347578 513532 92623 & 28242 3407 4090 & 1319336 510125 88533  \\
\hline
Eff.\ 90\%~total\slash module~1\slash module~4 & 8285 & 33935939 1926868 2923980 & 29137926 711464 2148856 & 4798013 1215404 775124 & 1063412 397880 72455 & 26928 3100 4307 & 1036484 394780 68148  \\
\hline
Eff.\ 100\%~total\slash module~1\slash module~4 & 9883 & 40379644 214092 366267 & 36443709 119498 3085536 & 3935935 945942 577141 & 896456 320005 59953 & 32121 3484 5551 & 864335 316521 54402  \\
\hline
\end{tabular}
\end{frame}

\end{document}
2

This is a variant, using the \Gape command, from makecell to give some vertical padding at the top and bottom of cells. I've put the repetitive ‘Number of` as a general heading for the last 7 columns:

\documentclass{beamer}
\usetheme{Malmoe}
\usepackage{array, makecell, bigstrut}
\newcolumntype{L}[1]{>{\raggedright\arraybackslash}m{#1}}
\newcolumntype{C}[1]{>{\centering\arraybackslash}m{#1}}
\renewcommand\theadfont{\tiny}

\begin{document}

\setcellgapes{5pt}
\begin{frame}{Statistics}{}
\tiny
\centering
\noindent
\begin{tabular}{| l | c | C{0.9cm} | *{5}{C{0.8cm}|} }
\multicolumn{1}{c}{} & \multicolumn{7}{c}{\scriptsize Number of}\\[1ex]%
\hline
 Scenario & Events & Clusters & Healthy clusters & Unhealthy clusters & Cluster pairs & \rule{0pt}{2.6ex}Real cluster pairs \rule[-1.2ex]{0pt}{2.5ex} & \rule{0pt}{2.6ex}Fake cluster pairs \rule[-1.2ex]{0pt}{2.5ex} \\
\hline
\Gape[3pt][2pt]{\makecell[lc]{Eff.\ 76\,\%~total\slash\\ module~1\slash\\ module~4}} & 9079 & 36855956 2191062 2917431 & 30235384 495474 1781164 & 6620572 1695588 1136267 & 1347578 513532 92623 & 28242 3407 4090 & 1319336 510125 88533 \\
\hline
\Gape[3pt][2pt]{\makecell[lc]{Eff.\ 90\,\%~total\slash\\ module~1\slash\\ module~4}} & 8285 & 33935939 1926868 2923980 & 29137926 711464 2148856 & 4798013 1215404 775124 & 1063412 397880 72455 & 26928 3100 4307 & 1036484 394780 68148 \\
\hline
\Gape[3pt][2pt]{\makecell[lc]{Eff.\ 100\,\%~total\slash\\ module~1\slash\\ module~4}} & 9883 & 40379644 214092 366267 & 36443709 119498 3085536 & 3935935 945942 577141 & 896456 320005 59953 & 32121 3484 5551 & 864335 316521 54402 \\
\hline
\end{tabular}
\end{frame}

\end{document} 

enter image description here

0

A version with {NiceTabular} of nicematrix. The key hvlines draws all the rules.

\documentclass{beamer}
\usetheme{Malmoe}
\usepackage{nicematrix}
\newcolumntype{L}[1]{>{\raggedright\arraybackslash}m{#1}}
\newcolumntype{C}[1]{>{\centering\arraybackslash}m{#1}}
\setlength\extrarowheight{2pt}

\begin{document}

\begin{frame}{Statistics}{}
\tiny
\centering
\begin{NiceTabular}{L{1.7cm}C{0.7cm}C{0.9cm}*{5}{C{0.8cm}}}[hvlines]
Scenario & Number of events & Number of clusters & Number of healthy clusters & Number of unhealthy clusters & Number of cluster pairs & Number of real cluster pairs & Number of fake cluster pairs \\
Eff.\ 76\%~total\slash module~1\slash module~4 & 9079 & 36855956 2191062 2917431 & 30235384 495474 1781164 & 6620572 1695588 1136267 & 1347578 513532 92623 & 28242 3407 4090 & 1319336 510125 88533  \\
Eff.\ 90\%~total\slash module~1\slash module~4 & 8285 & 33935939 1926868 2923980 & 29137926 711464 2148856 & 4798013 1215404 775124 & 1063412 397880 72455 & 26928 3100 4307 & 1036484 394780 68148  \\
Eff.\ 100\%~total\slash module~1\slash module~4 & 9883 & 40379644 214092 366267 & 36443709 119498 3085536 & 3935935 945942 577141 & 896456 320005 59953 & 32121 3484 5551 & 864335 316521 54402  \\
\end{NiceTabular}
\end{frame}

\end{document}

Output of the above code

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .