# Splitting a wide table or a longtable into two blocks

I have a very wide table (code below). I would like to put a small gap between the data under "First Group" and "Second Group" - two of the main multicolumns column headers. I tried putting in a double pipe (||) between these two columns where I specify the longtable. It splits the table but it behaves very weirdly in the multicolumn rows. How can I make the table split cleanly from top to bottom, hopefully without having to wade through the miles of code looking for &s? Thanks for your time!

Code for my table follows:

\documentclass[6pt]{article}
\usepackage[portrait, total={5.45in, 8.5in}, top=1.25in, bottom=1.25in, right=1.25in, left=1.5in, centering]{geometry}
\usepackage{longtable}
\usepackage{bm}
\usepackage[table]{xcolor}
\usepackage[none]{hyphenat}
\usepackage[T1]{fontenc}
\usepackage[default]{cantarell}
\usepackage{booktabs}

\pagestyle{empty}
\renewcommand{\familydefault}{\sfdefault}
\renewcommand{\arraystretch}{1.25}
\usepackage{arydshln}
\newcolumntype{x}[1]{>{\raggedright}p{#1}}
\setlength{\tabcolsep}{4pt}
\begin{document}

\begin{center}
\scriptsize{\textbf{A very wide table with two groups}}\end{center}
\setlength\LTleft{0in}
\setlength\LTright{1.25in}
\setlength\LTpre{-0.3cm}
\setlength\LTpost{0in}
\newcommand{\CTPanel}[1]{%
\multicolumn{1}{>{\columncolor{white}}r|}{#1}}
\centering
\begin{longtable}{lp{0.3cm}p{0.3cm}p{0.3cm}p{0.3cm}p{0.3cm}p{0.3cm}p{0.3cm}p{0.3cm}p{0.3cm}||p{0.3cm}p{0.3cm}p{0.3cm}p{0.3cm}p{0.3cm}p{0.3cm}p{0.3cm}p{0.3cm}p{0.3cm}p{0.3cm}}

\hiderowcolors
&\multicolumn{9}{c}{First Group}&\multicolumn{9}{c}{Second Group}\\\cmidrule(lr){2-10}\cmidrule(lr){11-19}
something&\multicolumn{2}{c}{AB} & \multicolumn{3}{c}{ABCD} & \multicolumn{4}{c||}{ABCD EFGH}&\multicolumn{2}{c}{AB} & \multicolumn{3}{c}{ABCD} & \multicolumn{4}{c}{ABCD EFGH}\\\cmidrule(lr){2-3}\cmidrule(lr){4-6}\cmidrule(lr){7-10}\cmidrule(lr){11-12}\cmidrule(lr){13-15}\cmidrule(lr){16-19}
Characteristics & + & - & I & II & III & $L^{A}$ & $L^{B}$ & $H^{+}$ & TN & + & - & I & II & III & $L^{A}$ & $L^{B}$ & $H^{+}$ & TN\\
\specialrule{0.02em}{0.1em}{0em}
\specialrule{0.02em}{0em}{0em}
\endfoot
\hline
\showrowcolors
some variable &+&+&-&+&+&-&-&-&-&-&+&+&-&-&+&+&-&-\\\hline
some other variable &+&+&-&+&+&-&-&-&-&-&+&+&-&-&+&+&-&-\\\hline
\end{longtable}
\end{document}


Resulting table (after edits suggested by D. Carlisle):

-

whenever you use a \multicolumn that ends in a column that has any | or @{...} material in its right hand edge, you need to re-insert it so if you have

|ll||ll|


then typically you will need

\multicolumn{2}{|c||}{heading for 1st 2 columns}&


This applies to all LaTeX tabular environments.

-
Thanks very much for the fast response. I will keep this helpful tip in mind for future tables. Unfortunately, it doesn't help this table completely. I shortened the number of columns for the only multicolumn subheading that crossed the || and have modified the multicolumns with ABCD EFGH and AB as suggested. Now the split doesn't make it in 2 of the rows with regular columns (the one with the H+ TN .. and the last row with "some other variable"). Is there another solution to splitting rather than fighting with pipes? – Ariel Feb 27 '12 at 13:35
Your vertical lines are there, but shifted up by strange amounts, whatever \cmidrule(lr){2-10}\cmidrule(lr){11-19} does it really doesn't like vertical rules. If I comment out each line that has those, the vertical lines shift back in to position. You could just use standard LaTeX \cline instead, possibly? – David Carlisle Feb 27 '12 at 14:36
I used \cmidrule from the booktabs package. The main advantage of using \cmidrule is that the rule does not touch the "walls" of the cell. Using \cline makes it appear as a continuous rule undistinguished from \hline. \cmidrule comes with a small space before and after the rule separating it from the text in the cells. I wonder if this space is interfering with the vertical rules. – Ariel Feb 27 '12 at 15:42
Yes I know but the booktabs documentation famously warns you that vertical rules are considered evil, so its horizontal rule commands not working with vertical rules may perhaps not be considered a bug. perhaps give up with the || and just have @{\hspace{....}} extra gap instead – David Carlisle Feb 27 '12 at 16:44
I ended up doing a hacky 5pt wide white vertical rule to achieve the separate blocks effect. (Attached a screenshot above). Not perfect, but better than the || solution. Thanks again for your help. – Ariel Feb 28 '12 at 15:41

Based on David Carlisle's answer and comments, this hack gives a better impression of the longtable being split into two distinct blocks. It uses a wide vertical white rule to split the parts of the table. Hence it looks better if the all the table rows (or just alternate rows) are coloured with a different colour other than white.

\begin{longtable}{lp{0.3cm}p{0.3cm}p{0.3cm}p{0.3cm}p{0.3cm}p{0.3cm}p{0.3cm}p{0.3cm}p{0.3cm}!{\color{white}\vrule width 5pt}p{0.3cm}p{0.3cm}p{0.3cm}p{0.3cm}p{0.3cm}p{0.3cm}p{0.3cm}p{0.3cm}p{0.3cm}p{0.3cm}}


One more interesting fact I learnt through this question is that it is possible to make vertical rules play well with multicolumns as well as the tricky booktabs package by using the vrule option.

For example, this code

\begin{longtable}{lp{0.3cm}!{\color{tableShade3}\vrule}
p{0.3cm}!{\color{white}\vrule width 4pt}
p{0.3cm}!{\color{white}\vrule}
p{0.3cm}!{\color{white}\vrule}
p{0.3cm}!{\color{white}\vrule}
p{0.3cm}!{\color{white}\vrule}
p{0.3cm}!{\color{white}\vrule}
p{0.3cm}!{\color{white}\vrule}
p{0.3cm}!{\color{white}\vrule}
p{0.3cm}!{\color{white}\vrule}
p{0.3cm}!{\color{white}\vrule}}