[Tex/LaTex] Latex Table goes outside page width

tableswidth

A mimimal working example of what I am facing right now:

\begin{table}
\centering

\begin{tabular}{|c|c|c|c|c|c|c|}
\hline
\multicolumn{1}{p{2cm}}{\centering Mass ($h^{-1}\;M_{\odot}$)}
& \multicolumn{1}{p{2cm}}{\centering $z$}
& \multicolumn{1}{p{2cm}}{\centering $r_{0}$} & 
$\gamma$ & $r_{0} \: (\gamma=2.0)$ & $N_{clusters}$ & bias \\ 
\hline
$M_{halo}>2\times10^{13}$ & $0.1<z_c<0.4$ & 9.89$\pm$0.20 & 1.76$\pm$0.05
             & 9.53$\pm$0.29 & 10492 & 1.81$\pm$0.03 \\ [1ex] 
        & $0.4<z_c<0.7$ & 10.22$\pm$0.14 & 1.84$\pm$0.04 & 10.01$\pm$0.17 & 27224 & 2.00$\pm$0.03 \\ [1ex] 
        & $0.7<z_c<1.0$ & 11.10$\pm$0.15 & 1.87$\pm$0.04 & 10.85$\pm$0.17 & 35133 & 2.52$\pm$0.02 \\ [1ex] 
        & $1.0<z_c<1.3$ & 11.62$\pm$0.23 & 1.98$\pm$0.05 & 11.58$\pm$0.19 & 31815 & 3.01$\pm$0.06 \\ [1ex] 
        & $1.3<z_c<1.6$ & 12.41$\pm$0.42 & 2.13$\pm$0.09 & 12.49$\pm$0.52 & 22978 & 3.37$\pm$0.19 \\ [1ex] 
        & $1.6<z_c<2.1$ & 14.78$\pm$0.21 & 2.06$\pm$0.05 & 14.78$\pm$0.22 & 18931 & 4.65$\pm$0.23 \\ [1ex] \hline \noalign{\vskip 0.1cm}    

\end{tabular} 

\caption{The best-fit values of the parameters of the real-space correlation function $\xi(r)$ for the light-cone at different (1) mass thresholds and (2) redshift ranges. For each sample we quote (3) the correlation length $r_{0}$, (4) slope $\gamma$, (5) correlation length $r_{0}$ at fixed slope $\gamma=2.0$, (6) number of clusters $N_{clusters}$ and (7) the bias $b$ obtained.} 
\label{table:clustering_with_mass}

\end{table}

and my table ends up going outside the specified page width, which looks like this.

enter image description here

I checked several answers of using tabularx etc, but they don't seem to work fine.

Best Answer

If you need to keep the table in portrait orientation, I would suggest that

  • you set the length parameters \thickmuskip and \medmuskip to 0mu;

  • simplify the structure of the second column;

  • get rid of the fixed-width header cell definitions;

  • use a tabular* environment instead of the tabular environment; and

  • switch from \normalsize to \small.

enter image description here

\documentclass{report}
\usepackage{amsmath}
\usepackage{booktabs}

\begin{document}
\begin{table}
\setlength\tabcolsep{0pt}
\setlength\thickmuskip{0mu}
\setlength\medmuskip{0mu}
\small
\begin{tabular*}{\textwidth}{c@{\extracolsep{\fill}}*{6}{c}}
\toprule
Mass  & $z_c$ & $r_{0}$ & $\gamma$ 
& $r_{0}$ ($\gamma=2.0$) & $N_{\textrm{clusters}}$ & bias \\ 
($h^{-1}M_{\odot}$)\\
\midrule
$M_{\textrm{halo}}>2\times10^{13}$ & $0.1\text{--}0.4$ & 9.89$\pm$0.20 & 1.76$\pm$0.05 & 9.53$\pm$0.29 & 10492 & 1.81$\pm$0.03 \\ \addlinespace 
& $0.4\text{--}0.7$ & 10.22$\pm$0.14 & 1.84$\pm$0.04 & 10.01$\pm$0.17 & 27224 & 2.00$\pm$0.03 \\ \addlinespace 
& $0.7\text{--}1.0$ & 11.10$\pm$0.15 & 1.87$\pm$0.04 & 10.85$\pm$0.17 & 35133 & 2.52$\pm$0.02 \\ \addlinespace 
& $1.0\text{--}1.3$ & 11.62$\pm$0.23 & 1.98$\pm$0.05 & 11.58$\pm$0.19 & 31815 & 3.01$\pm$0.06 \\ \addlinespace 
& $1.3\text{--}1.6$ & 12.41$\pm$0.42 & 2.13$\pm$0.09 & 12.49$\pm$0.52 & 22978 & 3.37$\pm$0.19 \\ \addlinespace 
& $1.6\text{--}2.1$ & 14.78$\pm$0.21 & 2.06$\pm$0.05 & 14.78$\pm$0.22 & 18931 & 4.65$\pm$0.23 \\ 
\bottomrule  

\end{tabular*} 

\caption[The best-fit values of the parameters of the real-space correlation function $\xi(r)$]{The best-fit values of the parameters of the real-space correlation function $\xi(r)$ for the light-cone at different (1)~mass thresholds and (2)~redshift ranges. For each sample we quote (3)~the correlation length $r_{0}$, (4)~slope $\gamma$, (5)~correlation length $r_{0}$ at fixed slope $\gamma=2.0$, (6)~number of clusters $N_{\textrm{clusters}}$, and (7)~the bias $b$ obtained.} 
\label{table:clustering_with_mass}

\end{table}
\end{document}
Related Question