![使表格适合页面宽度](https://linux22.com/image/298802/%E4%BD%BF%E8%A1%A8%E6%A0%BC%E9%80%82%E5%90%88%E9%A1%B5%E9%9D%A2%E5%AE%BD%E5%BA%A6.png)
我是 Latex 的新手,使用 booktab 制作表格。
我制作了一个 x 轴上有层次结构的表格,其中有 3 列,每列又有 3 个子列。但是,表格无法适应页面宽度,如下所示
我尝试了许多解决方案,例如 tabu、adjustbox、resize box 和 tabular*,但它们似乎无法解决问题,或者我不知道正确的语法。
我使用的代码附在下面,带有调整大小框。
\documentclass{article}
\usepackage{amsmath}
\usepackage{tabularx,booktabs}
\usepackage{array}
\usepackage{graphicx}
\newcolumntype{L}{>{$}l<{$}}
\newcolumntype{C}{>{$}c<{$}}
\newcolumntype{R}{>{$}r<{$}}
\newcommand{\nm}[1]{\textnormal{#1}}
\begin{document}
\begin{table} [h!]
\centering
\resizebox{\textwidth}{!} {%
\begin{tabular}{LCCCCCCCCC}
\toprule
\multicolumn{1}{l}{} &
\multicolumn{3}{c}{N N} &
\multicolumn{3}{c}{MM} &
\multicolumn{3}{c}{DW} \\
\cmidrule(lr){2-4}
\cmidrule(lr){5-7}
\cmidrule(lr){8-10}
&
\multicolumn{1}{c}{column One} &
\multicolumn{1}{c}{column two} &
\multicolumn{1}{c}{column One+col2} &
\multicolumn{1}{c}{column One} &
\multicolumn{1}{c}{column Two} &
\multicolumn{1}{c}{column One+col2} &
\multicolumn{1}{c}{column One} &
\multicolumn{1}{c}{column two} &
\multicolumn{1}{c}{column One+col2} \\
\midrule
experiment1 & a & b & c & d \\
experiment2 & p & q & r & s \\
\midrule[\heavyrulewidth]
\bottomrule
\end{tabular}%
}
\caption{Description of the table}\label{beta}
\end{table}
\end{document}
使用调整大小后我得到以下结果
有人能帮我吗?提前谢谢您。
答案1
不使用更高级方法(如旋转)的解决方案示例。它总结了我从评论中提出的建议。粗线显示文本的宽度并与原始(未缩放)示例分开。文本中有一些变化,但可能不会影响理解。
\documentclass{article}
\usepackage{amsmath}
\usepackage{tabularx,booktabs}
\usepackage{array}
\usepackage{graphicx}
\oddsidemargin-1cm
\textwidth17cm
\def\COMP#1{\begin{tabular}{c}#1\end{tabular}}
\newcolumntype{L}{>{$}l<{$}}
\newcolumntype{C}{>{$}c<{$}}
\newcolumntype{R}{>{$}r<{$}}
\newcommand{\nm}[1]{\textnormal{#1}}
\begin{document}
\begin{table} [h!]
\centering
%\resizebox{\textwidth}{!} {%
\begin{tabular}{LCCCCCCCCC}
\toprule
\multicolumn{1}{l}{} &
\multicolumn{3}{c}{N N} &
\multicolumn{3}{c}{MM} &
\multicolumn{3}{c}{DW} \\
\cmidrule(lr){2-4}
\cmidrule(lr){5-7}
\cmidrule(lr){8-10}
&
\multicolumn{1}{c}{\COMP{col.\\ One}} &
\multicolumn{1}{c}{\COMP{col.\\ two} }&
\multicolumn{1}{c}{\COMP{col.\\ One\\+col2}} &
\multicolumn{1}{c}{\COMP{col.\\ One}} &
\multicolumn{1}{c}{\COMP{col.\\ Two}} &
\multicolumn{1}{c}{\COMP{col.\\ One\\+col2}} &
\multicolumn{1}{c}{\COMP{col.\\ One}} &
\multicolumn{1}{c}{\COMP{col.\\ two}} &
\multicolumn{1}{c}{\COMP{col.\\ One\\+col2}} \\
\midrule
ex1 & a & b & c & d \\
ex2 & p & q & r & s \\
\midrule[\heavyrulewidth]
\bottomrule
\end{tabular}%
%}
\caption{Description of the table}\label{beta}
\end{table}
\noindent\rule{\textwidth}{1mm}
\begin{table} [h!]
\centering
%\resizebox{\textwidth}{!} {%
\begin{tabular}{LCCCCCCCCC}
\toprule
\multicolumn{1}{l}{} &
\multicolumn{3}{c}{N N} &
\multicolumn{3}{c}{MM} &
\multicolumn{3}{c}{DW} \\
\cmidrule(lr){2-4}
\cmidrule(lr){5-7}
\cmidrule(lr){8-10}
&
\multicolumn{1}{c}{column One} &
\multicolumn{1}{c}{column two} &
\multicolumn{1}{c}{column One+col2} &
\multicolumn{1}{c}{column One} &
\multicolumn{1}{c}{column Two} &
\multicolumn{1}{c}{column One+col2} &
\multicolumn{1}{c}{column One} &
\multicolumn{1}{c}{column two} &
\multicolumn{1}{c}{column One+col2} \\
\midrule
experiment1 & a & b & c & d \\
experiment2 & p & q & r & s \\
\midrule[\heavyrulewidth]
\bottomrule
\end{tabular}%
%}
\caption{Description of the table}\label{beta}
\end{table}
\end{document}
答案2
另一个解决方案
\documentclass{article}
\usepackage{amsmath}
\usepackage{tabularx,booktabs}
\usepackage{array}
\newcolumntype{C}[1]{>{\centering\let\newline\\\arraybackslash\hspace{0pt}}m{#1}}
\usepackage{graphicx}
\newcommand{\nm}[1]{\textnormal{#1}}
\begin{document}
\begin{table} [h!]
\centering
\resizebox{\textwidth}{!} {%
\begin{tabular}{@{\hspace{1cm}}cc cc cc cc c}
\toprule
\multicolumn{3}{c}{N N} &
\multicolumn{3}{c}{MM} &
\multicolumn{3}{c}{DW} \\
\cmidrule(lr){1-3}
\cmidrule(lr){4-6}
\cmidrule(lr){7-9}
\multicolumn{1}{C{1.5cm}}{column One} &
\multicolumn{1}{C{1.5cm}}{column two} &
\multicolumn{1}{C{1.5cm}}{column One+col2} &
\multicolumn{1}{C{1.5cm}}{column One} &
\multicolumn{1}{C{1.5cm}}{column Two} &
\multicolumn{1}{C{1.5cm}}{column One+col2} &
\multicolumn{1}{C{1.5cm}}{column One} &
\multicolumn{1}{C{1.5cm}}{column two} &
\multicolumn{1}{C{1.5cm}}{column One+col2} \\
\midrule
\multicolumn{9}{l}{Experiment 1}\\ \cmidrule{1-2}
a & b & c & d \\
\multicolumn{9}{l}{Experiment 2} \\ \cmidrule{1-2}
p & q & r & s \\
\midrule[\heavyrulewidth]
\bottomrule
\end{tabular}%
}
\caption{Description of the table}\label{beta}
\end{table}
\end{document}