Misaligned vertical lines in table

In my document I use different kinds of tables, as shown below in a simplified way. My problem only affects the first table shown in the output. Strangely, the vertical lines between columns "B" and "C" are misaligned. This error only occurs when I include package siunitx which however I need to create tables like the second one.

How can I avoid the misaligned vertical lines?

\documentclass[a4paper,preprint,3p]{elsarticle}

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

\begin{document}

{\scriptsize
\begin{tabular}{rr|rr|rr}
\hline
& A &   \multicolumn{2}{c}{B} & \multicolumn{2}{|c}{C} \\
& & B1 & B2 & C1 & C2 \\
\hline
1 & 2 & 3 & 2 & 1 & 2 \\
1 & 2 & 3 & 2 & 1 & 2 \\
\hline
\end{tabular}
}

\vspace{3cm}

{\scriptsize
\begin{tabular}{
lS[table-text-alignment=center, table-column-width = 0.47 cm, table-format=1.2]
S[table-text-alignment=center, table-column-width = 0.47 cm, table-format=1.2]
}
\hline
& {col 1} & {col 2} \\
\hline
line 1 & 1.22 & 1.13  \\
line 2 & 0.04 & 0.04 \\
\hline
\end{tabular}
}

\end{document}


1 Answer

Just shift the | to the first \multicolumn like

 & A &   \multicolumn{2}{c|}{B} & \multicolumn{2}{c}{C} \\


BTW, siunitx has nothing to do with this alignment. Place | carefully while using \multicolumn.

• Thank you for this solution! Works perfectly! Still I wonder why - in this example - the misalignment does not occur when siunitx is not included. – Aki Jul 26 '15 at 12:31
• @Aki you should get the misalignment with the array package because the rules take up horizontal space and are always at the right of the column never the left except the first column. Without array package rules take up no horizontal space and over-print the column space. – David Carlisle Jul 26 '15 at 16:13