我如何使这个宽表格在 LaTeX 中居中?

我如何使这个宽表格在 LaTeX 中居中?

我用 生成了一个非常宽的表格(比 还宽textwidthHmisc。表格太宽了,以至于使用居中时会自动左对齐。但是,我尝试过的所有方法都会出错,或者只是让表格保持左对齐。

\documentclass[a4paper,12pt]{report}
\setlength{\parskip}{1ex plus 0.5ex minus 0.2ex}
\linespread{2}
\usepackage{setspace}
\usepackage{booktabs,caption,fixltx2e}
\usepackage{subfig}
\usepackage{adjustbox}
\captionsetup{belowskip=12pt,aboveskip=4pt}

\begin{document}


\begin{table}[h!]
\footnotesize
\begin{center}
\begin{tabular}{lrrrcrrrcrrrcrrr}
\hline\hline
\multicolumn{1}{l}{\bfseries Trans}&\multicolumn{3}{c}{\bfseries 50}&\multicolumn{1}{c}{\bfseries }&\multicolumn{3}{c}{\bfseries 100}&\multicolumn{1}{c}{\bfseries }&\multicolumn{3}{c}{\bfseries 200}&\multicolumn{1}{c}{\bfseries }&\multicolumn{3}{c}{\bfseries 400}\tabularnewline
\cline{2-4} \cline{6-8} \cline{10-12} \cline{14-16}
\multicolumn{1}{l}{}&\multicolumn{1}{c}{b0}&\multicolumn{1}{c}{b1}&\multicolumn{1}{c}{b2}&\multicolumn{1}{c}{}&\multicolumn{1}{c}{b0}&\multicolumn{1}{c}{b1}&\multicolumn{1}{c}{b2}&\multicolumn{1}{c}{}&\multicolumn{1}{c}{b0}&\multicolumn{1}{c}{b1}&\multicolumn{1}{c}{b2}&\multicolumn{1}{c}{}&\multicolumn{1}{c}{b0}&\multicolumn{1}{c}{b1}&\multicolumn{1}{c}{b2}\tabularnewline
\hline
{\bfseries No}&&&&&&&&&&&&&&&\tabularnewline
~~fw&$0.83$&$$&$-0.0017$&&$0.90$&$ 0.01018$&$-1.2e-03$&&$0.94$&$$&$$&&$0.97$&$$&$-0.00042$\tabularnewline
~~bw&$0.88$&$$&$$&&$0.94$&$$&$$&&$$&$$&$$&&$0.98$&$$&$$\tabularnewline
~~sp&$0.81$&$0.0031$&$$&&$$&$$&$$&&$$&$$&$$&&$$&$$&$$\tabularnewline
\hline
{\bfseries Blom}&&&&&&&&&&&&&&&\tabularnewline
~~fw&$1.00$&$$&$$&&$1.00$&$-0.00024$&$ 2.3e-05$&&$1.00$&$$&$$&&$1.00$&$$&$$\tabularnewline
~~bw&$0.90$&$$&$-0.0667$&&$0.95$&$$&$-9.1e-02$&&$0.97$&$$&$$&&$0.99$&$$&$$\tabularnewline
~~sp&$0.81$&$$&$$&&$0.90$&$-0.07838$&$-9.6e-02$&&$0.95$&$$&$$&&$0.98$&$$&$$\tabularnewline
\hline
{\bfseries Log}&&&&&&&&&&&&&&&\tabularnewline
~~fw&$0.86$&$$&$$&&$0.92$&$$&$$&&$$&$$&$$&&$$&$$&$$\tabularnewline
~~bw&$$&$$&$$&&$$&$$&$-9.4e-03$&&$$&$$&$$&&$$&$$&$$\tabularnewline
~~sp&$$&$$&$$&&$$&$$&$$&&$$&$$&$$&&$$&$$&$$\tabularnewline
\hline
\end{tabular}
\end{center}
\end{table}


\end{document}

我尝试了在本网站和其他网站上能找到的所有方法,但还是找不到适合我的解决方案。

答案1

使用\resizebox

\documentclass[a4paper,12pt]{report}
\usepackage{graphicx}
\usepackage{booktabs,caption,fixltx2e}
\usepackage{subfig}
\captionsetup{belowskip=12pt,aboveskip=4pt}

\begin{document}

\begin{table}[htb!]
\resizebox{\linewidth}{!}{\def\arraystretch{1.5}%
\begin{tabular}{lrrrcrrrcrrrcrrr}
\hline\hline
\multicolumn{1}{l}{\bfseries Trans}&\multicolumn{3}{c}{\bfseries 50}&\multicolumn{1}{c}{\bfseries }&\multicolumn{3}{c}{\bfseries 100}&\multicolumn{1}{c}{\bfseries }&\multicolumn{3}{c}{\bfseries 200}&\multicolumn{1}{c}{\bfseries }&\multicolumn{3}{c}{\bfseries 400}\tabularnewline
\cline{2-4} \cline{6-8} \cline{10-12} \cline{14-16}
\multicolumn{1}{l}{}&\multicolumn{1}{c}{b0}&\multicolumn{1}{c}{b1}&\multicolumn{1}{c}{b2}&\multicolumn{1}{c}{}&\multicolumn{1}{c}{b0}&\multicolumn{1}{c}{b1}&\multicolumn{1}{c}{b2}&\multicolumn{1}{c}{}&\multicolumn{1}{c}{b0}&\multicolumn{1}{c}{b1}&\multicolumn{1}{c}{b2}&\multicolumn{1}{c}{}&\multicolumn{1}{c}{b0}&\multicolumn{1}{c}{b1}&\multicolumn{1}{c}{b2}\tabularnewline
\hline
\bfseries No&&&&&&&&&&&&&&&\tabularnewline
~~fw&$0.83$&$$&$-0.0017$&&$0.90$&$ 0.01018$&$-1.2e-03$&&$0.94$&$$&$$&&$0.97$&$$&$-0.00042$\tabularnewline
~~bw&$0.88$&$$&$$&&$0.94$&$$&$$&&$$&$$&$$&&$0.98$&$$&$$\tabularnewline
~~sp&$0.81$&$0.0031$&$$&&$$&$$&$$&&$$&$$&$$&&$$&$$&$$\tabularnewline
\hline
\bfseries Blom&&&&&&&&&&&&&&&\tabularnewline
~~fw&$1.00$&$$&$$&&$1.00$&$-0.00024$&$ 2.3e-05$&&$1.00$&$$&$$&&$1.00$&$$&$$\tabularnewline
~~bw&$0.90$&$$&$-0.0667$&&$0.95$&$$&$-9.1e-02$&&$0.97$&$$&$$&&$0.99$&$$&$$\tabularnewline
~~sp&$0.81$&$$&$$&&$0.90$&$-0.07838$&$-9.6e-02$&&$0.95$&$$&$$&&$0.98$&$$&$$\tabularnewline
\hline
\bfseries Log&&&&&&&&&&&&&&&\tabularnewline
~~fw&$0.86$&$$&$$&&$0.92$&$$&$$&&$$&$$&$$&&$$&$$&$$\tabularnewline
~~bw&$$&$$&$$&&$$&$$&$-9.4e-03$&&$$&$$&$$&&$$&$$&$$\tabularnewline
~~sp&$$&$$&$$&&$$&$$&$$&&$$&$$&$$&&$$&$$&$$\tabularnewline
\hline
\end{tabular}}
\end{table}

\end{document}

如果您希望它比线宽更宽但居中,请使用:

[...]
\begin{table}[htb!]
\makebox[\textwidth]{\resizebox{1.1\linewidth}{!}{\def\arraystretch{1.5}%
\begin{tabular}{lrrrcrrrcrrrcrrr}
[...]
\end{tabular}}}

第一个是1.1\textwidth,第二个是\textwidth

在此处输入图片描述

答案2

您没有正确使用booktabs;例如,您不需要添加虚拟列。然后,使用,siunitx您可以确保数据的外观统一。最后,adjustbox可以轻松重新调整表格以适应。

\documentclass[a4paper,12pt]{report}
\usepackage{booktabs,siunitx}
\usepackage{adjustbox}

\begin{document}


\begin{table}[!htp]
\centering
\begin{adjustbox}{max width=\columnwidth}
\begin{tabular}{@{}
 l
 S[table-format=1.2]
 S[table-format=1.4]
 S[table-format=-1.4]
 %
 S[table-format=1.2]
 S[table-format=-1.5]
 S[table-format=-1.1e-1]
 %
 S[table-format=1.2]
 S[table-format=1.2]% actually empty
 S[table-format=1.2]% actually empty
 %
 S[table-format=1.2]
 S[table-format=1.2]% actually empty
 S[table-format=-1.5]
@{}}
\toprule
\multicolumn{1}{l}{\bfseries Trans}&
  \multicolumn{3}{c}{\bfseries 50}&
  \multicolumn{3}{c}{\bfseries 100}&
  \multicolumn{3}{c}{\bfseries 200}&
  \multicolumn{3}{c}{\bfseries 400}\\
\cmidrule(lr){2-4} \cmidrule(lr){5-7} \cmidrule(lr){8-10} \cmidrule(l){11-13}
& {b0} & {b1} & {b2} & {b0} & {b1} & {b2} & {b0} & {b1} & {b2} & {b0} & {b1} & {b2} \\
\midrule
{\bfseries No}\\
fw & 0.83 &        & -0.0017 & 0.90 & 0.01018 & -1.2e-03 & 0.94 & & & 0.97 & & -0.00042 \\
bw & 0.88 &        &         & 0.94 &         &          &          & 0.98 & &          \\
sp & 0.81 & 0.0031 &         &      &         &          &          &      & &          \\
\midrule
{\bfseries Blom}\\
fw & 1.00 &        &         & 1.00 &-0.00024 & 2.3e-05  & 1.00 & & & 1.00 & &          \\
bw & 0.90 &        & -0.0667 & 0.95 &         &-9.1e-02  & 0.97 & & & 0.99 & &          \\
sp & 0.81 &        &         & 0.90 &-0.07838 &-9.6e-02  & 0.95 & & & 0.98 & &          \\
\midrule
{\bfseries Log}\\
fw & 0.86 &        &         & 0.92 &         &          &      & & &      & &          \\
bw &      &        &         &      &         &-9.4e-03  &      & & &      & &          \\
sp &      &        &         &      &         &          &      & & &      & &          \\
\bottomrule
\end{tabular}
\end{adjustbox}
\end{table}

\end{document}

在此处输入图片描述

答案3

 \hspace*{-\textwidth}\begin{tabular}
 ...
 \end{tabular}\hspace*{-\textwidth}

将隐藏宽度,使其位于文本块的中心并渗入边距/

相关内容