2

Set up

Using the MWE below I'm trying to centre "Heading 1" with the 4 subheadings, and "Headings 2" and "Heading 3" with their subheadings respectively:

MWE

\documentclass[12pt, oneside]{book}

%MARGIN SETTINGS
    \usepackage{geometry}
    \geometry{
    paper=a4paper, 
    inner=2.5cm, 
    outer=2.5cm, 
    bindingoffset=0.0cm, 
    top=2.5cm, 
    bottom=2.5cm,
    headsep=4.5mm, 
    footskip=7.4mm, 
    %showframe
    }

%FOR TABLES
\usepackage{float}
\usepackage{graphicx} 

\usepackage{booktabs}
\usepackage{multirow}
\usepackage{siunitx}
\newcolumntype{?}{!{\vrule width 1pt}}


%----------------------BEGIN-------------------------

\begin{document}


\begin{table}[H]
\centering
\resizebox{\textwidth}{!}{%
  \begin{tabular}{l|l ? S|S|S|S  ? S|S ? S|S} %S centres
  %\begin{tabular}{l|l ? S|S|S|S  | S|S | S|S}
    \toprule
    \multirow{2}{*}{Column 1} & 
    \multirow{2}{*}{Column 2} &  %& &
      \multicolumn{2}{c}{Heading 1} & %& 
      \multicolumn{2}{c}{Heading 2} & 
      \multicolumn{2}{c}{Heading 3} \\
       & & {Sub 1} & {Sub 2} & {Sub 3} & {Sub 4} & {Sub 1} & {Sub 2} & {Sub 1} & {Sub 2} \\
          \midrule
    A1 = item1 & 0.0001  & 1 & 1 & 1 & 2 & 3 & 4 & 5 & 6 \\
    %\hline
    A2 = item2 & 0.0002 & 1 & 1 & 7 & 8 & 9 & 10 & 11 & 12 \\
    %\hline
    A3 = item3 & 0.0003  & 1 & 1 & 13 & 14 & 15 & 16 & 17 & 18 \\
    \bottomrule
  \end{tabular}}
    \caption{Test Table} \label{tbl:BPF}
\end{table}

\end{document}

The Problem

If i use more &'s to align the headings i get the following error. The vertical lines have overflowed to the top:

enter image description here

Goal

How to centre the headings (as above) but without the overflowing vertical lines in between "Sub 1 Sub 2" and "Sub 4 Sub 1"

1

I'm not sure, what you want. Do you mean like this? If so: you have to specify the correct number of columns in \multicolumn (4 in case of "Heading 1"). To have the vertical rules, just add those to the column type specification of \multicolumn.

\documentclass[12pt, oneside]{book}

%MARGIN SETTINGS
    \usepackage{geometry}
    \geometry{
    paper=a4paper, 
    inner=2.5cm, 
    outer=2.5cm, 
    bindingoffset=0.0cm, 
    top=2.5cm, 
    bottom=2.5cm,
    headsep=4.5mm, 
    footskip=7.4mm, 
    %showframe
    }

%FOR TABLES
\usepackage{float}
\usepackage{graphicx} 

\usepackage{booktabs}
\usepackage{multirow}
\usepackage{siunitx}
\newcolumntype{?}{!{\vrule width 1pt}}


%----------------------BEGIN-------------------------

\begin{document}


\begin{table}[H]
\centering
\resizebox{\textwidth}{!}{%
  \begin{tabular}{l|l ? S|S|S|S  ? S|S ? S|S} %S centres
  %\begin{tabular}{l|l ? S|S|S|S  | S|S | S|S}
    \toprule
    \multirow{2}{*}{Column 1} & 
    \multirow{2}{*}{Column 2} &  %& &
      \multicolumn{4}{c?}{Heading 1} & %& 
      \multicolumn{2}{c?}{Heading 2} & 
      \multicolumn{2}{c}{Heading 3} \\
       & & {Sub 1} & {Sub 2} & {Sub 3} & {Sub 4} & {Sub 1} & {Sub 2} & {Sub 1} & {Sub 2} \\
          \midrule
    A1 = item1 & 0.0001  & 1 & 1 & 1 & 2 & 3 & 4 & 5 & 6 \\
    %\hline
    A2 = item2 & 0.0002 & 1 & 1 & 7 & 8 & 9 & 10 & 11 & 12 \\
    %\hline
    A3 = item3 & 0.0003  & 1 & 1 & 13 & 14 & 15 & 16 & 17 & 18 \\
    \bottomrule
  \end{tabular}}
    \caption{Test Table} \label{tbl:BPF}
\end{table}

\end{document}

enter image description here

In general it is considered as bad practice to resize a table. Instead you could use \small to make it fit in the text width. Also, tables tend to look better with less (read 'no') vertical lines. You might consider to use the following:

\documentclass[12pt, oneside]{book}

%MARGIN SETTINGS
    \usepackage{geometry}
    \geometry{
    paper=a4paper, 
    inner=2.5cm, 
    outer=2.5cm, 
    bindingoffset=0.0cm, 
    top=2.5cm, 
    bottom=2.5cm,
    headsep=4.5mm, 
    footskip=7.4mm, 
    %showframe
    }

%FOR TABLES
\usepackage{float}
\usepackage{graphicx} 

\usepackage{booktabs}
\usepackage{multirow}
\usepackage{siunitx}


%----------------------BEGIN-------------------------

\begin{document}


\begin{table}[H]
  \small
\centering
  \begin{tabular}{ll  SSSS   SS  SS} %S centres
  %\begin{tabular}{l|l ? S|S|S|S  | S|S | S|S}
    \toprule
     & &
      \multicolumn{4}{c}{Heading 1} & %& 
      \multicolumn{2}{c}{Heading 2} & 
      \multicolumn{2}{c}{Heading 3} \\
      \cmidrule(rl){3-6}
      \cmidrule(rl){7-8}
      \cmidrule(rl){9-10}
     Column 1& Column 2& {Sub 1} & {Sub 2} & {Sub 3} & {Sub 4} & {Sub 1} & {Sub 2} & {Sub 1} & {Sub 2} \\
          \midrule
    A1 = item1 & 0.0001  & 1 & 1 & 1 & 2 & 3 & 4 & 5 & 6 \\
    %\hline
    A2 = item2 & 0.0002 & 1 & 1 & 7 & 8 & 9 & 10 & 11 & 12 \\
    %\hline
    A3 = item3 & 0.0003  & 1 & 1 & 13 & 14 & 15 & 16 & 17 & 18 \\
    \bottomrule
  \end{tabular}
    \caption{Test Table} \label{tbl:BPF}
\end{table}

\end{document}

enter image description here

  • Yes! Exactly like that. Is there also an option to have the bold lines in-between "Sub 4 Sub 1" and "Sub 2 Sub 1" to overflow to the top? As it is in the original image? (i.e the same hight as is in-between "column2 Sub1"). – UniStuffz Feb 21 '18 at 22:32

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.