如何调整表格大小以适合页面宽度(不改变字体大小)?
\documentclass[twocolumn,a4paper]{article}
\usepackage{multirow}
\begin{document}
\begin{table}[h]
\begin{tabular}{c|c|c|c|c}
\hline
\multirow{2}{*}{Types} & \multicolumn{4}{c}{Days} \\ \cline{2-5}
& Day 1 & Day 2 & Day 3 & Day 4 \\ \hline
Type 1 & 12-06-08-07-09-08-18-32-48-101-108& 13-88-08-07-09-08-14-39-36-10 & 56-33-08-07-09-08-18-32-48&26-29-26\\ \hline
Type 2 & 01-07-10-22-55-07-100-32-48& 08-18-32-48-66-36-10 &26-29-26& 10-55-21\\ \hline
\end{tabular}
\end{table}
\end{document}
表格超出了页面的宽度:
期望输出:
答案1
由于您不想减小字体大小,因此必须引入换行符。您可能希望使用包tabularx
及其tabularx
环境,修改该包的X
列类型以将第 2 列至第 5 列的内容置于中心。
\documentclass[twocolumn,a4paper]{article}
\usepackage{multirow,tabularx}
\newcolumntype{C}{>{\centering\arraybackslash}X}
\begin{document}
\begin{table*}
\begin{tabularx}{\textwidth}{@{} l|C|C|C|C @{}}
\hline
\multirow{2}{*}{Types} & \multicolumn{4}{c}{Days} \\
\cline{2-5}
& Day 1 & Day 2 & Day 3 & Day 4 \\ \hline
Type 1 & 12-06-08-07-09-08-18-32-48-101-108& 13-88-08-07-09-08-14-39-36-10 & 56-33-08-07-09-08-18-32-48&26-29-26\\ \hline
Type 2 & 01-07-10-22-55-07-100-32-48& 08-18-32-48-66-36-10 &26-29-26& 10-55-21\\
\hline
\end{tabularx}
\end{table*}
\end{document}
PS 如果字符串“Type 1”和“Type 2”需要垂直居中,只需将它们放在\multirow{2}{*}{...}
语句中即可。
附录:您可能想考虑让您的表格看起来更“开放”或“通风”。一种方法是删除所有垂直线,并使用包的宏来booktabs
获得间距合适的水平线。
\documentclass[twocolumn,a4paper]{article}
\usepackage{tabularx,booktabs}
\newcolumntype{C}{>{\centering\arraybackslash}X}
\begin{document}
\begin{table*}
\begin{tabularx}{\textwidth}{@{} lCCCC @{}}
\toprule
Types & \multicolumn{4}{c@{}}{Days} \\
\cmidrule(l){2-5}
& Day 1 & Day 2 & Day 3 & Day 4 \\
\midrule
Type 1 & 12-06-08-07-09-08-18-32-48-101-108& 13-88-08-07-09-08-14-39-36-10 & 56-33-08-07-09-08-18-32-48&26-29-26\\
\addlinespace
Type 2 & 01-07-10-22-55-07-100-32-48& 08-18-32-48-66-36-10 &26-29-26& 10-55-21\\
\bottomrule
\end{tabularx}
\end{table*}
\end{document}
答案2
\documentclass[twocolumn,a4paper]{article}
\usepackage{multirow}
\usepackage{array}
\usepackage{showframe}
\newcolumntype{M}{>{\centering\arraybackslash}m{3.1cm}}
\begin{document}
\begin{table*}[htb]
\centering
\begin{tabular}{|c|M|M|M|M|}
\hline
\multirow{2}{*}{Types} & \multicolumn{4}{c|}{Days} \\ \cline{2-5}
& Day 1 & Day 2 & Day 3 & Day 4 \\ \hline
Type 1 & 12-06-08-07-09-08-18-32-48-101-108& 13-88-08-07-09-08-14-39-36-10 & 56-33-08-07-09-08-18-32-48&26-29-26\\ \hline
Type 2 & 01-07-10-22-55-07-100-32-48& 08-18-32-48-66-36-10 &26-29-26& 10-55-21\\ \hline
\end{tabular}
\end{table*}
\end{document}