我正在使用下面给出的模板在 LaTeX Beamer 中制作表格。
我的表格总共有 11 列,但最后 3 列不在表格框内。有人能帮帮我吗?
\documentclass{article}
\usepackage[usenames,dvipsnames]{xcolor}
\usepackage{tcolorbox}
\usepackage{tabularx}
\usepackage{array}
\usepackage{colortbl}
\tcbuselibrary{skins}
\begin{document}
\begin{adjustbox}{width=0.7\textwidth}
\begin{tcolorbox}[tabgris,tabularx={c|c|c|c|c|c|c|c|c|c|c}, boxrule=0.5pt, title =Comparison of computed torque and thrust with experimental data for various meshes]
S.no.& \multicolumn{2}{c|} {Mesh size (million points)} & \multicolumn{4}{c|} {Torque (Nm)} & \multicolumn{4}{c} {Thrust (N)} \\
& Coarse & Fine & Exp. & Coarse & Fine & Diff*(\%) & Exp. & Coarse & Fine & Diff*(\%) \\ \hline \hline
1& 1.13 & 8.60 & 804.0 & 686.1 & 719.0 & -4.6 & 1157.0 & 1094.1 & 1123.0 & -2.6 \\ \hline
2& 1.45 & 11.0 & 804.0 & 691.2 & 713.1 & -3.0 & 1157.0 & 1091.2 & 1115.1 & -2.2 \\ \hline
3& 1.70 & 13.0 & 804.0 & 690.0 & 719.2 & -4.0 & 1157.0 & 1091.3 & 1120.3 & -2.6\\ \hline
4& 1.90 & 14.6 & 804.0 & 676.1 & 701.3 & -3.6 & 1157.0 & 1076.0 & 1110.0 & -3.1
\end{tcolorbox}
\end{adjustbox}
\end{document}
答案1
我理解,该表格应该出现在beamer
透明胶片上...即,它的文本宽度和使用的字体大小非常有限。
用于将整个表格宽度限制为\textwidth
,仅仅使用 是不够的\tabularx
,您必须以正确的方式使用它!您应该使用来自\tabularx
( X
) 的列类型,而不是来自tabular
( l
、c
、r
或p{...}
否则,具有更宽内容的单元格将不遵守规定的表格宽度并将导致具有此类单元格的表格行将超出定义的右表格边框,甚至可能超出文本边框(就像您遇到的情况一样)。
\documentclass{beamer}
\usepackage{tabularx}
\renewcommand\tabularxcolumn[1]{b{#1}}% <-- improve appearance of column heads
\newcolumntype{C}{>{\centering\arraybackslash}X}% <-- main change
\usepackage{colortbl}
\usepackage{tcolorbox}
\begin{document}
\begin{frame}
\tiny
\setlength\tabcolsep{1pt}
\begin{tcolorbox}[tabularx={ C | *{9}{C|}C},% <-- main change
boxrule=0.5pt,
title = Comparison of computed torque and thrust
with experimental data for various meshes]
& \multicolumn{2}{>{\setlength\hsize{2\hsize}}C|} {Mesh size\newline (million points) } % <-- main change
& \multicolumn{4}{c|} {Torque (Nm)}
& \multicolumn{4}{c} {Thrust (N)} \\
S. no. & Coarse & Fine & Exp. & Coarse & Fine & Diff*(\%) & Exp. & Coarse & Fine & Diff*(\%) \\ \hline \hline
1 & 1.13 & 8.60 & 804.0 & 686.1 & 719.0 & -4.6 & 1157.0 & 1094.1 & 1123.0 & -2.6 \\ \hline
2 & 1.45 & 11.0 & 804.0 & 691.2 & 713.1 & -3.0 & 1157.0 & 1091.2 & 1115.1 & -2.2 \\ \hline
3 & 1.70 & 13.0 & 804.0 & 690.0 & 719.2 & -4.0 & 1157.0 & 1091.3 & 1120.3 & -2.6 \\ \hline
4 & 1.90 & 14.6 & 804.0 & 676.1 & 701.3 & -3.6 & 1157.0 & 1076.0 & 1110.0 & -3.1
\end{tcolorbox}
\end{frame}
\end{document}
附录:
如果表格宽度超过\textwidth
,则可以使用包changepage
并局部增加\textwidth
,例如4.4em
。在这种情况下,您可以使用更大的字体大小(\scriptsize
而不是\tiny
)。MWE:
\documentclass{beamer}
\usepackage{tabularx}
\renewcommand\tabularxcolumn[1]{b{#1}}% <-- added
\newcolumntype{C}{>{\centering\arraybackslash}X}% <-- added
\usepackage{colortbl}
\usepackage{tcolorbox}
\usepackage{changepage}%<-- added
\begin{document}
\begin{frame}
\begin{adjustwidth}{-2.2em}{-2.2em}
\scriptsize
\setlength\tabcolsep{1pt}
\begin{tcolorbox}[tabularx={ c | *{9}{C|}C},% <--- main change
boxrule=0.5pt,
title = Comparison of computed torque and thrust
with experimental data for various meshes]
& \multicolumn{2}{>{\setlength\hsize{2\hsize}}C|}{Mesh size\newline (million points) }% <--- main change
& \multicolumn{4}{c|} {Torque (Nm)}
& \multicolumn{4}{c} {Thrust (N)} \\
S. no. & Coarse & Fine & Exp. & Coarse & Fine & Diff*(\%) & Exp. & Coarse & Fine & Diff*(\%) \\ \hline \hline
1 & 1.13 & 8.60 & 804.0 & 686.1 & 719.0 & -4.6 & 1157.0 & 1094.1 & 1123.0 & -2.6 \\ \hline
2 & 1.45 & 11.0 & 804.0 & 691.2 & 713.1 & -3.0 & 1157.0 & 1091.2 & 1115.1 & -2.2 \\ \hline
3 & 1.70 & 13.0 & 804.0 & 690.0 & 719.2 & -4.0 & 1157.0 & 1091.3 & 1120.3 & -2.6 \\ \hline
4 & 1.90 & 14.6 & 804.0 & 676.1 & 701.3 & -3.6 & 1157.0 & 1076.0 & 1110.0 & -3.1
\end{tcolorbox}
\end{adjustwidth}
\end{frame}
\end{document}
答案2
您的表格无法容纳在颜色框内,您可以减小字体大小并\tabcolsep
控制列间空间
\documentclass{article}
\usepackage[usenames,dvipsnames]{xcolor}
\usepackage{lipsum}
\usepackage{tabularx}
\usepackage{colortbl}
\usepackage{tcolorbox}
\tcbuselibrary{skins}
\setlength{\tabcolsep}{2pt} % inter columns space
\begin{document}
\lipsum[1]
\begin{scriptsize}
\begin{tcolorbox}[tabularx={c|c|c|c|c|c|c|c|c|c|c}, boxrule=0.5pt, title =Comparison of computed torque and thrust with experimental data for various meshes]
S.no.& \multicolumn{2}{c|} {Mesh size (million points)} & \multicolumn{4}{c|} {Torque (Nm)} & \multicolumn{4}{c} {Thrust (N)} \\
& Coarse & Fine & Exp. & Coarse & Fine & Diff*(\%) & Exp. & Coarse & Fine & Diff*(\%) \\ \hline \hline
1& 1.13 & 8.60 & 804.0 & 686.1 & 719.0 & -4.6 & 1157.0 & 1094.1 & 1123.0 & -2.6 \\ \hline
2& 1.45 & 11.0 & 804.0 & 691.2 & 713.1 & -3.0 & 1157.0 & 1091.2 & 1115.1 & -2.2 \\ \hline
3& 1.70 & 13.0 & 804.0 & 690.0 & 719.2 & -4.0 & 1157.0 & 1091.3 & 1120.3 & -2.6\\ \hline
4& 1.90 & 14.6 & 804.0 & 676.1 & 701.3 & -3.6 & 1157.0 & 1076.0 & 1110.0 & -3.1
\end{tcolorbox}
\end{scriptsize}
\end{document}
输出