我正在使用 beamer 文档类制作一张科学海报,但是创建的表格所包含的项目的对齐方式不正确。
例如,如表格所示,值和单词位于每个单元格的中上部,而不是其本身的中心。这是我使用的表格的代码:
\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
这是“带格”(或“笼状”)桌子的标准问题。
在下面的代码中,我使用\scriptsize
使表格适合并添加与字母“g”在基线以下延伸的量相对应的高度。
请注意输入的大幅简化。
\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}
答案2
软件包的解决方案cellspace
,它允许您使用以字母 S(或 C,如果您使用 ,或任何您想要的字母,带有加载时间选项)为前缀的说明符来定义列中单元格顶部和底部的最小垂直间距。软件包还为列标题提供siunitx
帮助。makecell
\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}
答案3
我减小了字体大小并在行上方添加了小空间。
此外,还可以减少表格的宽度。例如,p 值中的小数位数可以减少到 3 位,列名可以分成多行;例如,您可以使用较短的列名并添加注释以进行解释等。表格会变得更窄,略高,但可能会更好地适应框架并改善其呈现效果,这是一个温和的建议
\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}