I have some questions about the below table:
- If I omit the margins, the table will completely get disordered.
- I want to have the two 4 columns in the middle to have a slight distance with each other but the \cmidrule is not working properly
- as you can see at the right side of the table the data have come out of the table.
I will be more than grateful if you kindly help me solve the problems.
\documentclass{article} [8pt]
\usepackage[margin=1cm]{geometry}
\usepackage{tabularx}
\usepackage{booktabs}
\usepackage{amsmath}
\usepackage{mhchem}
\usepackage{siunitx}
\usepackage{bm}
\begin{document}
\begin{table*}[htb]
\label{tbl:stats-and-correlations}
\begin{tabularx}{\linewidth}{l*{8}{c}}
\toprule
& \multicolumn{4}{c}{\textbf{Panel A:}}
& \multicolumn{4}{c}{\textbf{Panel B:}} \\ \cmidrule{2-5} \cmidrule{6-9}
& {$d_{(\ce{O1}-\ce{Mg_{(Zn)}})} $} & {$d_{(\ce{O1}-\ce{Mg_{(Zn)}})} $} & {$d_{(\ce{O1}-\ce{Mg_{(Zn)}})} $} & {$d_{(\ce{O1}-\ce{Mg_{(Zn)}})} $} & {$d_{(\ce{O1}-\ce{Mg_{(Zn)}})} $} & {$d_{(\ce{O1}-\ce{Mg_{(Zn)}})} $} & {$d_{(\ce{O1}-\ce{Mg_{(Zn)}})} $}
& {$d_{(\ce{O1}-\ce{Mg_{(Zn)}})} $} \\ [0.5ex]
& (\si{\angstrom})
& (\si{\angstrom})
& (\si{\angstrom})
& (\si{\angstrom})
& (\si{\angstrom})
& (\si{\angstrom})
& (\si{\angstrom})
& (\si{\angstrom}) \\
\hline
Variable~1 & 0.78 & 0.37 & 0.48 & 0.10 & 0.13 & 0.58 & 0.41 & 0.10\\
Variable~2 & 0.46 & 0.86 & 0.96 & 0.44 & 0.15 & 0.56 & 0.31 & 0.10\\
Variable~3 & 0.03 & 0.75 & 0.11 & 0.44 & 0.71 & 0.06 & 0.26 & 0.10\\
Variable~4 & 0.21 & 0.25 & 0.38 & 0.88 & 0.24 & 0.52 & 0.46 & 0.10\\
Variable~5 & 0.20 & 0.93 & 0.54 & 0.96 & 0.55 & 0.82 & 0.62 & 0.10\\
Variable~6 & 0.67 & 0.85 & 0.74 & 0.99 & 0.27 & 0.48 & 0.85 & 0.10\\
Variable~7 & 0.82 & 0.89 & 0.68 & 0.06 & 0.02 & 0.30 & 0.10 & 0.10\\
\bottomrule
\end{tabularx}
\end{table*}
\end{document}
Best Answer
Your table is wider then the available
\linewidth
and thetabularx
is used without anyX
column.One possibility to get the table right is using
\small
and defining the first column as anX
column:Code:
Note that I have changed
\hline
to\midrule
.Another possibility is using
\small
together withtabular*
and @{\extracolsep{\fill}} behind the first column definition.will stretch all columns so that the width of the table fits
\linewidth
.Or you can use
\resizebox
from thegraphics
bundle if your table width differs not so much from line width.Code
Additionally you can save space by removing the left
\tabcolsep
of the first column and the right\tablcolsep
of the last column: add@{}
at the begin and the end of the column definitions. That means for the last example