[Tex/LaTex] How to center this wide table in LaTeX

horizontal alignmenttables

I have a very wide table (wider than textwidth) generated with Hmisc. The table is so wide that when centering is used it is automatically left aligned. However, everything that I have tried gives an error or just keeps the table left alligned.

\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}

I have tried everything that could find on this site and on other sites, but can not find a solution that works for me.

Best Answer

use \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}

and if you want it wider than the linewidth but centered use:

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

the first one is 1.1\textwidth and the second \textwidth:

enter image description here

Related Question