1

I´m making a scientific poster with the beamer documentclass, but the tables created show an incorrect alignment of the items they contained.

For example as shown in the table, the values and the words are located a bit on the middle-top of each cell, instead of the center of itself. Here is the code for the table I´m using:

\begin{table}[h]
\begin{tabular}{l|cc|cc|}
\cline{2-5}
                                                                             & \multicolumn{2}{c|}{\cellcolor[HTML]{F8FF00}\textbf{Protein yield}}                                                 & \multicolumn{2}{c|}{\cellcolor[HTML]{68CBD0}\textbf{Carbohydrates yield}}                                           \\ \hline
\multicolumn{1}{|l|}{\cellcolor[HTML]{FE996B}\textbf{Factor}}                & \multicolumn{1}{c|}{\cellcolor[HTML]{FAFC9D}\textit{p-value}} & \cellcolor[HTML]{FAFC9D}\textit{Contribution  / \%} & \multicolumn{1}{c|}{\cellcolor[HTML]{B1E5E8}\textit{p-value}} & \cellcolor[HTML]{B1E5E8}\textit{Contribution  / \%} \\ \hline
\multicolumn{1}{|l|}{\cellcolor[HTML]{FFE0BB}\textit{Microalgae Biomass}}    & \multicolumn{1}{c|}{{\color[HTML]{FE0000} 0.0000}}            & 89.5                                                & \multicolumn{1}{c|}{{\color[HTML]{FE0000} 0.0000}}            & 83.2                                                \\ \hline
\multicolumn{1}{|l|}{\cellcolor[HTML]{FFE0BB}\textit{Pretreatment}}          & \multicolumn{1}{c|}{{\color[HTML]{FE0000} 0.0004}}            & 1.6                                                 & \multicolumn{1}{c|}{{\color[HTML]{FE0000} 0.0000}}            & 8.2                                                 \\ \hline
\multicolumn{1}{|l|}{\cellcolor[HTML]{FFE0BB}\textit{NADES}}                 & \multicolumn{1}{c|}{{\color[HTML]{FE0000} 0.0212}}            & 0.6                                                 & \multicolumn{1}{c|}{0.0837}                                   & 0.3                                                 \\ \hline
\multicolumn{1}{|l|}{\cellcolor[HTML]{FFE0BB}\textit{Solvent:Biomass Ratio}} & \multicolumn{1}{c|}{{\color[HTML]{FE0000} 0.0001}}            & 2.2                                                 & \multicolumn{1}{c|}{0.5269}                                   & 0.1                                                 \\ \hline
\multicolumn{1}{|l|}{\cellcolor[HTML]{FFE0BB}\textit{Temperature}}           & \multicolumn{1}{c|}{{\color[HTML]{FE0000} 0.0046}}            & 0.9                                                 & \multicolumn{1}{c|}{0.1270}                                   & 0.3                                                 \\ \hline
\multicolumn{1}{|l|}{\cellcolor[HTML]{FFE0BB}\textit{Contact Time}}          & \multicolumn{1}{c|}{{\color[HTML]{FE0000} 0.0269}}            & 0.6                                                 & \multicolumn{1}{c|}{{\color[HTML]{FE0000} 0.0291}}            & 0.5                                                 \\ \hline
\multicolumn{1}{|l|}{\cellcolor[HTML]{FFE0BB}\textit{NADES Concentration}}   & \multicolumn{1}{c|}{{\color[HTML]{FE0000} 0.0072}}            & 0.8                                                 & \multicolumn{1}{c|}{0.3719}                                   & 0.1                                                 \\ \hline
\multicolumn{1}{|l|}{\cellcolor[HTML]{FFE0BB}\textit{Interaction}}           & \multicolumn{1}{c|}{{\color[HTML]{FE0000} 0.0000}}            & 2.4                                                 & \multicolumn{1}{c|}{{\color[HTML]{FE0000} 0.0000}}            & 5.9                                                 \\ \hline
\end{tabular}
\end{table}
1
  • 1
    To me they seem in fact centered. Note that some characters have descenders, such as g or y, and what you perceive as whitespace below the text is just the space for these descenders. I would suggest that you increase the line spacing a bit, for example using \renewcommand{\arraystretch}{1.2} (to be added before \begin{tabluar}). Sep 22, 2022 at 9:00

3 Answers 3

1

This is a standard problem with “ruled” (or “caged”) tables.

In the code below I use \scriptsize to make the table fit and add height corresponding to the amount the letter “g” extends below the baseline.

Note the vast simplifications to the input.

\documentclass[xcolor=table]{beamer}

% shorthands for cellcolors
\newcommand{\CC}[1]{\cellcolor[HTML]{#1}}
\newcommand{\SC}[1]{\color[HTML]{#1}}

\begin{document}

\begin{frame}

\scriptsize
\setlength{\extrarowheight}{\fontchardp\font`g}

\begin{tabular}{|l|c|c|c|c|}
\cline{2-5}
\multicolumn{1}{c|}{}
& \multicolumn{2}{c|}{\CC{F8FF00}\textbf{Protein yield}}
& \multicolumn{2}{c|}{\CC{68CBD0}\textbf{Carbohydrates yield}}
\\
\hline
\CC{FE996B}\textbf{Factor}
& \CC{FAFC9D}\textit{p-value} & \CC{FAFC9D}\textit{Contribution/\%}
& \CC{B1E5E8}\textit{p-value} & \CC{B1E5E8}\textit{Contribution/\%}
\\
\hline
\CC{FFE0BB}\textit{Microalgae Biomass}    & \SC{FE0000} 0.0000 & 89.5 & \SC{FE0000} 0.0000 & 83.2
\\ \hline
\CC{FFE0BB}\textit{Pretreatment}          & \SC{FE0000} 0.0004 &  1.6 & \SC{FE0000} 0.0000 &  8.2
\\ \hline
\CC{FFE0BB}\textit{NADES}                 & \SC{FE0000} 0.0212 &  0.6 &             0.0837 &  0.3
\\ \hline
\CC{FFE0BB}\textit{Solvent:Biomass Ratio} & \SC{FE0000} 0.0001 &  2.2 &             0.5269 &  0.1
\\ \hline
\CC{FFE0BB}\textit{Temperature}           & \SC{FE0000} 0.0046 &  0.9 &             0.1270 &  0.3
\\ \hline
\CC{FFE0BB}\textit{Contact Time}          & \SC{FE0000} 0.0269 &  0.6 & \SC{FE0000} 0.0291 &  0.5
\\ \hline
\CC{FFE0BB}\textit{NADES Concentration}   & \SC{FE0000} 0.0072 &  0.8 &             0.3719 &  0.1
\\ \hline
\CC{FFE0BB}\textit{Interaction}           & \SC{FE0000} 0.0000 &  2.4 & \SC{FE0000} 0.0000 &  5.9
\\ \hline
\end{tabular}

\end{frame}

\end{document}

enter image description here

1

A solution with the cellspace package, which lets you define minimal vertical spacings at the top and bottom of cells in columns with specifiers prefixed with the letter S (or C if you use siunitx, or any letter you please with a loading time option). Also a help from the makecell package for the column heads.

    \documentclass[table]{beamer}
    \usepackage{makecell}
    \usepackage{cellspace}
    \setlength{\cellspacetoplimit}{4pt}
    \setlength{\cellspacebottomlimit}{4pt}

    \begin{document}

    \begin{frame}
    \renewcommand{\theadfont}{\small\itshape}
    \small
      \begin{table}[h]
    \begin{tabular}{l|ScSc|ScSc|}
    \cline{2-5}
     & \multicolumn{2}{c|}{\cellcolor[HTML]{F8FF00}\textbf{Protein yield}} & \multicolumn{2}{c|}{\cellcolor[HTML]{68CBD0}\textbf{Carbohydrates yield}} \\ \hline
    \multicolumn{1}{|l|}{\cellcolor[HTML]{FE996B}\textbf{Factor}} & \multicolumn{1}{c|}{\cellcolor[HTML]{FAFC9D}\textit{p-value}} & \cellcolor[HTML]{FAFC9D}\thead{Contribution\\ / \%} & \multicolumn{1}{c|}{\cellcolor[HTML]{B1E5E8}\textit{p-value}} & \cellcolor[HTML]{B1E5E8}\thead{Contribution\\ / \%} \\ \hline
    \multicolumn{1}{|l|}{\cellcolor[HTML]{FFE0BB}\textit{Microalgae Biomass}} & \multicolumn{1}{c|}{{\color[HTML]{FE0000} 0.0000}} & 89.5 & \multicolumn{1}{c|}{{\color[HTML]{FE0000} 0.0000}} & 83.2 \\ \hline
    \multicolumn{1}{|l|}{\cellcolor[HTML]{FFE0BB}\textit{Pretreatment}} & \multicolumn{1}{c|}{{\color[HTML]{FE0000} 0.0004}} & 1.6 & \multicolumn{1}{c|}{{\color[HTML]{FE0000} 0.0000}} & 8.2 \\ \hline
    \multicolumn{1}{|l|}{\cellcolor[HTML]{FFE0BB}\textit{NADES}} & \multicolumn{1}{c|}{{\color[HTML]{FE0000} 0.0212}} & 0.6 & \multicolumn{1}{c|}{0.0837} & 0.3 \\ \hline
    \multicolumn{1}{|l|}{\cellcolor[HTML]{FFE0BB}\textit{Solvent:Biomass Ratio}} & \multicolumn{1}{c|}{{\color[HTML]{FE0000} 0.0001}} & 2.2 & \multicolumn{1}{c|}{0.5269} & 0.1 \\ \hline
    \multicolumn{1}{|l|}{\cellcolor[HTML]{FFE0BB}\textit{Temperature}} & \multicolumn{1}{c|}{{\color[HTML]{FE0000} 0.0046}} & 0.9 & \multicolumn{1}{c|}{0.1270} & 0.3 \\ \hline
    \multicolumn{1}{|l|}{\cellcolor[HTML]{FFE0BB}\textit{Contact Time}} & \multicolumn{1}{c|}{{\color[HTML]{FE0000} 0.0269}} & 0.6 & \multicolumn{1}{c|}{{\color[HTML]{FE0000} 0.0291}} & 0.5 \\ \hline
    \multicolumn{1}{|l|}{\cellcolor[HTML]{FFE0BB}\textit{NADES Concentration}} & \multicolumn{1}{c|}{{\color[HTML]{FE0000} 0.0072}} & 0.8 & \multicolumn{1}{c|}{0.3719} & 0.1 \\ \hline
    \multicolumn{1}{|l|}{\cellcolor[HTML]{FFE0BB}\textit{Interaction}} & \multicolumn{1}{c|}{{\color[HTML]{FE0000} 0.0000}} & 2.4 & \multicolumn{1}{c|}{{\color[HTML]{FE0000} 0.0000}} & 5.9 \\ \hline
    \end{tabular}
    \end{table}
    \end{frame}

    \end{document} 

enter image description here

1

I have decreased font size and add small space above rows.

Also, it's possible to reduce width of the table. A number of decimal places e.g. in p-values can be reduced to 3, column names can be split into multiple lines; e.g. you could have shorter column names and add annotation for an explanation etc. The table would become narrower and slightly taller but might better fit the frame and improve its presentation as a gentle suggestion

enter image description here

\documentclass{beamer}
\usepackage{array}
\usepackage{booktabs}
\usepackage{siunitx}
\usepackage{xcolor,colortbl}

\sisetup{
  round-mode = places,
}

\definecolor{pyield}{HTML}{F8FF00}
\definecolor{cyield}{HTML}{68CBD0}
\definecolor{fheading}{HTML}{FE996B}
\definecolor{fnames}{HTML}{FFE0BB}
\definecolor{pvalue}{HTML}{FF0000}

\newcommand\xgrthead[1]{\textbf{#1}}
\newcommand\xcname[1]{\textit{#1}}
\newcommand\TB[1]{\begin{tabular}[t]{@{}c@{}}#1\end{tabular}}
\newcommand\pvalsig[1]{%
  \textcolor{pvalue}{\tablenum[table-format=1.3,round-precision=3]{#1}}}


\begin{document}
\begin{frame}
  \begin{table}[h]
    \setlength\extrarowheight{1pt}
    \fontsize{8pt}{10pt}\selectfont
    \begin{tabular}{
      >{\columncolor{fnames}}l
      c
      S[table-format=2.1,round-precision=1]
      S[table-format=1.3,round-precision=3]
      S[table-format=2.1,round-precision=1]
    }
      \cline{2-5}
      \multicolumn{1}{c}{\cellcolor{white}}
        & \multicolumn{2}{c}{\cellcolor{pyield}\xgrthead{\TB{Protein\\yield}}}
        & \multicolumn{2}{c}{\cellcolor{cyield}\xgrthead{\TB{Carbohydrates\\yield}}} \\
      \hline
      \cellcolor{fheading}\xgrthead{Factor}
        & {\cellcolor{pyield!35}\xcname{p-value}}
        & {\cellcolor{pyield!35}\xcname{Contr.$^{*}$}}
        & {\cellcolor{cyield!35}\xcname{p-value}}
        & {\cellcolor{cyield!35}\xcname{Contr.$^{*}$}} \\
      \hline
      \xcname{Microalgae Biomass}    & \pvalsig{0.0000} & 89.5 & \pvalsig{0.0000} & 83.2 \\
      \xcname{Pretreatment}          & \pvalsig{0.0004} &  1.6 & \pvalsig{0.0000} &  8.2 \\
      \xcname{NADES}                 & \pvalsig{0.0212} &  0.6 &          0.0837  &  0.3 \\
      \xcname{Solvent:Biomass Ratio} & \pvalsig{0.0001} &  2.2 &          0.5269  &  0.1 \\
      \xcname{Temperature}           & \pvalsig{0.0046} &  0.9 &          0.1270  &  0.3 \\
      \xcname{Contact Time}          & \pvalsig{0.0269} &  0.6 & \pvalsig{0.0291} &  0.5 \\
      \xcname{NADES Concentration}   & \pvalsig{0.0072} &  0.8 &          0.3719  &  0.1 \\
      \xcname{Interaction}           & \pvalsig{0.0000} &  2.4 & \pvalsig{0.0000} &  5.9 \\
      \hline
      \cellcolor{white} & \multicolumn{4}{@{}c@{}}{$^{*}$\footnotesize Contributions displayed in (\%)}
    \end{tabular}
  \end{table}
\end{frame}
\end{document}

You must log in to answer this question.

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