0

my problem: I have several tables spanning multiple pages each (longtable) with about 100-150 rows. I want the numbers in the tables formatted so that they are aligned at the decimal point with 2 times 2 numbers per cell and a vertical line (|) in the center. In addition some of the numbers are bold. The | should align over all rows within each table.

Thus far, I managed to get that right. However, the issue is that if a number gets larger (e.g., >100) than additional white space is added after the number, thus leading to the undesired formatting as shown in the MWE. I would like to have the two numbers in each row being tight around the | so as to say align right for the first number and aligned left for the second number.

I also tried the siunitx package as I read it is more flexible but I was not able to get it working with bold numbers.

MWE:

\documentclass{article}
\usepackage{newtxtext}
\usepackage{array}
\newcolumntype{L}[1]{>{\raggedright\let\\\arraybackslash\hspace{0pt}}m{#1}}
\newcolumntype{C}[1]{>{\centering\let\\\arraybackslash\hspace{0pt}}m{#1}}
\usepackage{longtable}
\usepackage{dcolumn}
\usepackage{makecell}
\usepackage{calc}
\usepackage{multirow}
\newcommand{\mr}{\multirow}
\newcommand{\mc}{\multicolumn}

\begin{document}

\newcolumntype{.}{D{.}{.}{-1}}
\makeatletter
\newcolumntype{B}[3]{>{\boldmath\DC@{#1}{#2}{#3}}c<{\DC@end}}
\makeatother
\begin{longtable}{L{3.6cm}|>{\centering}m{2.2cm}|.c.|.c.}
\hline\hline
&  X & \mc{6}{c}{Some header text}\\
Y & Z & \mc{3}{C{2.75cm}}{A} & \mc{3}{C{2.75cm}}{B}\\
\hline
\endfirsthead
\mc{4}{c}%
{\tablename\thetable\ -- \textit{Continued from previous page}} \\
\hline\hline
&  X & \mc{6}{c}{Some header text}\\
Y & Z & \mc{3}{C{2.75cm}}{A} & \mc{3}{C{2.75cm}}{B}\\
\hline
\endhead
\hline \mc{8}{r}{\textit{Continued on next page}}
\endfoot
\hline
\endlastfoot
\mr{2}{*}{A1} & \mr{2}{*}{N1} & \mc{1}{B{.}{.}{-1}}{-2.8} & | & 3.1 & 2.4 & | &  0.8 \\
 &   &  0.9 & |  &  2.4 &   0.8 & |  &  3.7 \\
\mr{2}{*}{A2} & \mr{2}{*}{N2} & -200.8 & | & 3.1 & \mc{1}{B{.}{.}{-1}}{-5.4} & | &  0.8 \\
 &   &  0.9 & |  &  2.4 &   0.8 & |  &  3.7 \\
\hline
\end{longtable}
\end{document}

which produces: enter image description here

1 Answer 1

1

You are using D..{-1} which always puts the . in the centre of the column. Chose a better format for each column, so

D..{4.1} D..{1.1} D..{2.1} D..{1.1}

for

widest entries

-200.8 & 3.1 & -5.4 & 3.7

1
  • Thanks. Works great but for the alignment of the bold numbers. Do you have any suggestions for that?
    – Jan
    Commented Jul 6, 2020 at 11:31

You must log in to answer this question.

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