4

I have some questions about the below table:

  1. If I omit the margins, the table will completely get disordered.
  2. 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
  3. 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}
5
  • Use \cmidrule(lr){2-5} to shorten the rule on either side (left, right).
    – Johannes_B
    Aug 5, 2014 at 8:01
  • Btw: Those cmidrule are working properly and as documented. You specifically need to trim thos using the optional argument.
    – Johannes_B
    Aug 5, 2014 at 8:08
  • The rules typeset by booktabs are limited to the textwidth. You table is just toooo huge. Consider to put it landscape.
    – Johannes_B
    Aug 5, 2014 at 8:09
  • The same reason lets the bit stand out to the right a bit. Use \geometry{showframe}` to verify.
    – Johannes_B
    Aug 5, 2014 at 8:13
  • What is that [8pt] doing there after the \documentclass? You could add a \small after \begin{table*} to make the table a bit smaller. Aug 5, 2014 at 8:15

2 Answers 2

2

Your table is wider then the available \linewidth and the tabularx is used without any X column.

One possibility to get the table right is using \small and defining the first column as an X column:

enter image description here

Code:

\documentclass{article}
\usepackage[margin=1cm]{geometry}
\usepackage{tabularx}
\usepackage{booktabs}
\usepackage{amsmath}
\usepackage[version=3]{mhchem} 
\usepackage{siunitx}
%\usepackage{bm}
\begin{document}
\begin{table*}[htb]
  \label{tbl:stats-and-correlations}
  \small\begin{tabularx}{\linewidth}{X*{8}{c}}
    \toprule
    & \multicolumn{4}{c}{\textbf{Panel A:}} & \multicolumn{4}{c}{\textbf{Panel B:}}\\ \cmidrule(r){2-5} \cmidrule(l){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}) \\
    \midrule
    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}

Note that I have changed \hline to \midrule.


Another possibility is using \small together with tabular* and @{\extracolsep{\fill}} behind the first column definition.

\small\begin{tabular*}{\linewidth}{l@{\extracolsep{\fill}}*{8}{c}}
...
\end{tabular*}

will stretch all columns so that the width of the table fits \linewidth.

enter image description here


Or you can use \resizebox from the graphics bundle if your table width differs not so much from line width.

enter image description here

Code

\documentclass{article}
\usepackage[margin=1cm]{geometry}
\usepackage{tabularx}
\usepackage{booktabs}
\usepackage{amsmath}
\usepackage[version=3]{mhchem}% loads also graphicx
\usepackage{siunitx}
%\usepackage{bm}
\begin{document}
\begin{table*}[htb]
  \label{tbl:stats-and-correlations}
  \resizebox{\linewidth}{!}{\begin{tabular}{l*{8}{c}}
    \toprule
    & \multicolumn{4}{c}{\textbf{Panel A:}} & \multicolumn{4}{c}{\textbf{Panel B:}}\\ \cmidrule(r){2-5} \cmidrule(l){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}) \\
    \midrule
    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{tabular}}
\end{table*}
\end{document}

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

\resizebox{\linewidth}{!}{\begin{tabular}{@{}l*{8}{c}@{}}
...
\end{tabular}}

enter image description here

0
2

Given that all of your column headers are the same, and the d_{(\ce{O1}-\ce{Mg_{(Zn)}} is what is causing the columns to be so wide, I suggest combining all of the column labels. Incorporating the triming suggestions of @Johannes_B from the comments above you can get:

enter image description here

by writing

\documentclass{article}
\usepackage[margin=1cm]{geometry}
\usepackage{booktabs}
\usepackage{amsmath}
\usepackage{mhchem}
\usepackage{siunitx}
\usepackage{bm}
\begin{document}

\begin{table*}[htb]
  \label{tbl:stats-and-correlations}

  \begin{tabular}{l*{4}l*4{c}}
    \toprule
    \
    & \multicolumn{4}{c}{\textbf{Panel A:}}
     & \multicolumn{4}{c}{\textbf{Panel B:}}  \\ \cmidrule(r){2-5} \cmidrule(l){6-9}
    &\multicolumn {4}{c}{$d_{(\ce{O1}-\ce{Mg_{(Zn)}})} $ (\si{\angstrom})}
     &\multicolumn {4}{c}{$d_{(\ce{O1}-\ce{Mg_{(Zn)}})} $ (\si{\angstrom})} \\[0.8ex]
               \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{tabular}

\end{table*}

\end{document}
9
  • You should remove the [8pt] option in the first line because it's misplaced (it should come before, not after, {article}) and - more importantly - because the article document class doesn't even recognize [8pt] as an option.
    – Mico
    Aug 5, 2014 at 9:02
  • @Mico Thanks. Done. Hadn't looked at the preamble at all...
    – user30471
    Aug 5, 2014 at 9:04
  • What is tabularx supposed to do, since you're not using X columns?
    – egreg
    Aug 5, 2014 at 9:09
  • @egreg I agree, it's unnecessary.
    – user30471
    Aug 5, 2014 at 11:13
  • The columns are not the same in the title. I just put the "d" parameters as samples here.
    – sryzdn
    Aug 5, 2014 at 13:18

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .