1

I have the following script that generates a table that I am trying to format properly.

\documentclass[12pt]{article}

\usepackage{float}
\usepackage{booktabs}
\usepackage{graphicx}
\usepackage{multirow}

\begin{document}

\begin{table}[H]

\begin{tabular}{c@{\qquad}cccc@{\qquad}ccc@{\qquad}ccc@{\qquad}c}
  \toprule
  \multirow{2}{*}{\raisebox{-\heavyrulewidth}{Scenarios}} & \multicolumn{4}{c}  {GAM} & \multicolumn{3}{c}{SCAM} & \multicolumn{3}{c}{Krig} \\
  \cmidrule{2-10}
  & {\tt tp} & {\tt cr} & {\tt ps} & {\tt ad} & {\tt mpi} & {\tt cv} & {\tt   micv} & {\tt mat} & {\tt sph} & {\tt exp}\\
  \midrule
  Uniform & 1 & 2 & 3 & 1 & 2 & 3 \\
  1 dominant & 1 & 2 & 3 & 1 & 2 & 3 \\
  \bottomrule
\end{tabular}

\end{table}

\end{document}

The headers "GAM", "SCAM" and "Krig" are slightly off-centre (pushed to the right). How can this be fixed?

Also, I need the horizontal line below the "Krig" header to extend further to the right. I tried increasing the 10 to 15 in \cmidrule, but received an error.

Does someone know how this can be fixed? Any assistance is greatly appreciated.

1
0

Rather than changing the intercolumn space for some columns, add some empty columns. Also, to fine-tune the vertical placement of the multirowcell, use the optional argument of \multirow rather than \raisebox:

\documentclass[12pt]{article}

\usepackage{float}
\usepackage{booktabs}
\usepackage{graphicx}
\usepackage{array, multirow}

\begin{document}

\begin{table}[H]
\begin{tabular}{l@{\qquad}*{14}{c}}
  \toprule
  \multirow{2}{*}[-\heavyrulewidth]{Scenarios}} & \multicolumn{4}{c} {GAM} & & \multicolumn{3}{c}{SCAM} & & \multicolumn{3}{c}{Krig} \\
 \cmidrule(r){2-5} \cmidrule(lr){7-9} \cmidrule(lr){11-13}
  & {\tt tp} & {\tt cr} & {\tt ps} & {\tt ad} & & {\tt mpi} & {\tt cv} & {\tt micv} & & {\tt mat} & {\tt sph} & {\tt exp}\\
  \midrule
  Uniform & 1 & 2 & 3 & 1 & & 2 & 3 \\
  1 dominant & 1 & 2 & 3 & 1 & & 2 & 3 \\
  \bottomrule
\end{tabular}
\end{table}

\end{document} 

enter image description here

0

Use the optional spacing (contraction) arguments of \cmidrule; \cmidrule(<side>){<cols>} contracts a rule spanning <cols> at the <sides>, where <sides> identify the left or right of the rule. This aids in breaking sub-headings from the rest of the table horizontally.

enter image description here

\documentclass{article}

\usepackage{booktabs}

\begin{document}

\begin{tabular}{ l *{4}{c} *{3}{c} *{3}{c} }
  \toprule
  & \multicolumn{4}{c}{GAM} & \multicolumn{3}{c}{SCAM} & \multicolumn{3}{c}{Krig} \\
  \cmidrule(lr){2-5} % GAM
  \cmidrule(lr){6-8} % SCAM
  \cmidrule(lr){9-11} % Krig
  Scenarios & 
    \texttt{tp} & \texttt{cr} & \texttt{ps} & \texttt{ad} & % GAM
    \texttt{mpi} & \texttt{cv} & \texttt{micv} & % SCAM
    \texttt{mat} & \texttt{sph} & \texttt{exp} \\ % Krig
  \midrule
  Uniform    & 
    1 & 2 & 3 & 4 & % GAM
    5 & 6 & 7 & % SCAM
    8 & 9 & 10 \\ % Krig
  1 dominant & 
    1 & 2 & 3 & 4 & % GAM
    5 & 6 & 7 & % SCAM
    8 & 9 & 10 \\ % Krig
  \bottomrule
\end{tabular}

\end{document}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.