# alignment of numbers in exponential format in a table with complicated header rows

I have a table that contains a lot of numbers. I have been defining new column types to allow me to specify column widths and allow \newline within a cell. Some of my columns of numbers are in exponential format. I previously had these as text, like "0.496E+07" but to be consistent with the rest of the document, I have just converted them to \num{0.496e7} using siunitx. The problem is that now the numbers are not aligned.

I am unsure how I could use the S column type because I don't know how to redefine it with a width as I have with R{width} for r for example.

I tried using \tablenum but everything scoots out of the RHS of the table column, and I can't work out whether I can fix that using table-format.

\documentclass[12pt, a4paper, oneside, fleqn]{report}

% Page geometry etc
%----------------------------
\usepackage{setspace}                % allow different line spacing
\renewcommand{\topfraction}{0.85}
\renewcommand{\textfraction}{0.1}

% Maths stuff
%------------
\usepackage{siunitx}
\usepackage{multirow}
\usepackage{array}
\renewcommand{\arraystretch}{1.5}
\newcolumntype{L}[1]{>{\raggedright\let\newline\\\arraybackslash\hspace{0pt}}m{#1}}
\newcolumntype{C}[1]{>{\centering\let\newline\\\arraybackslash\hspace{0pt}}m{#1}}
\newcolumntype{R}[1]{>{\raggedleft\let\newline\\\arraybackslash\hspace{0pt}}m{#1}}

\setlength{\tabcolsep}{0.11cm}

\begin{document}

\onehalfspacing

\begin{table}
\centering
\footnotesize
\begin{tabular}{|L{3.2cm} || r | R{2.0cm}  | r| R{1.1cm} || r | R{2.0cm}| r  | R{1.1cm} | }
\hline
\multirow{2}{*}{ } &  \multicolumn{4}{ c ||}{\textbf{Full Selection}} & \multicolumn{4}{ c |}{\textbf{Max Condition Number $\mathbf{10^6}$}}\tabularnewline  \cline{2-9}
\hline
\textbf{1:}             &     210 & \num{0.496E+07} &  84.3  &   0.40   &    153 &     \num{0.8126E+06} &  69.3   &   0.45 \\
\textbf{2:}  8 Clear 1.3 WVE       &     183 & \num{0.130E+11} & 207.1  &   1.13   &     76 &     \num{0.9469E+06} &  91.5   &   1.20 \\ [1ex]

\hline
\end{tabular}
\caption{caption }

\end{table}

\end{document}


Here's what the output looks like, note the lack of alignment in column 3:

As usual, any table that uses \multirow can immediately improved by removing it.

Use the features in siunitx, which go much beyond \num. As you see, you have to do just one measurement: the tabular, without the local setting of \tabcolsep is overfull by 9.52791pt, so I just cut off the necessary space doing a simple division. The exact result is .595494375pt, but 0.6 is just as good.

Please, avoid single vertical rules and abhor double vertical rules.

\documentclass[12pt, a4paper, oneside, fleqn]{report}
\usepackage{geometry}
\geometry{
top=2.5cm,
left=3.5cm,
bottom=2.5cm,
right=2.5cm,
showframe,
}

\usepackage{siunitx}
\usepackage{array,booktabs}

\bfseries
\begin{tabular}{@{}c@{}}
\strut#1\strut
\end{tabular}%
}

\begin{document}

\begin{table}
\centering
\footnotesize
%%% Without the following, the overfull is 9.52791pt;
%%% since there are nine columns and so 16 intercolumn
%%% spaces, do 9.52791/16=0.6
\begin{tabular}{
@{}
l
S[table-format=3.0]
S[table-format=1.3e2]
S[table-format=3.1]
S[table-format=1.2]
S[table-format=3.0]
S[table-format=1.4e2]
S[table-format=3.1]
S[table-format=1.2]
@{}
}
\toprule
& \multicolumn{4}{c}{\bfseries Full Selection} &
\multicolumn{4}{c}{\bfseries\boldmath Max Condition Number $10^6$} \\
\cmidrule(lr){2-5} \cmidrule(l){6-9} % no "r" here because it's the last column
\midrule
\textbf{1:}                 & 210 & 0.496E+07 &  84.3 & 0.40 & 153 & 0.8126E+06 & 69.3 & 0.45 \\
\textbf{2:} 8 Clear 1.3 WVE & 183 & 0.130E+11 & 207.1 & 1.13 &  76 & 0.9469E+06 & 91.5 & 1.20 \\
\bottomrule
\end{tabular}

\caption{caption}

\end{table}

\end{document}


• Wow, that's amazing!. Obviously I knew it was a mess, but I had no idea I could remove so much. Thanks also for the pretty comprehensive list of what table-format can do. I notice everyone round here hates vertical rules - I think I'm a bit old-fashioned, I 'grew up' producing excel tables in the '90's :-) – FionaSmith May 23 '14 at 15:52
• One quick question: best to check, presumably the change to tabcolsep remains within this table environment? – FionaSmith May 23 '14 at 15:53
• @FionaSmith Boxing cells is useful when looking at a worksheet; not at all when looking at a typeset table. Yes, the setting to \tabcolsep is only in the table environment. I don't think it's a good thing to set it globally in the preamble. Not to 1.1mm, anyway. – egreg May 23 '14 at 15:55

It is possible to use two different column types simultaneously for a tabular column, e.g., both an S column (with suitably set options, see below) to typeset numerical entries in scientific/exponential format and something like

\multicolumn{1}{R{2.0cm}|}{...}


to typeset the information in the two corresponding header cells. Note that you should eliminate the \num wrappers from the numbers in question. I would also get rid of the double vertical lines.

\documentclass[12pt, a4paper, oneside, fleqn]{report}

% Page geometry etc
\usepackage{setspace} % allow different line spacing
\renewcommand{\topfraction}{0.85}
\renewcommand{\textfraction}{0.1}

\usepackage{siunitx}
%%\usepackage{multirow} % not needed
%%\usepackage{array}    % not needed

% tabular stuff
\newcolumntype{L}[1]{>{\raggedright\let\newline\\\arraybackslash\hspace{0pt}}m{#1}}
\newcolumntype{C}[1]{>{\centering\let\newline\\\arraybackslash\hspace{0pt}}m{#1}}
\newcolumntype{R}[1]{>{\raggedleft\let\newline\\\arraybackslash\hspace{0pt}}m{#1}}

\setlength{\tabcolsep}{0.11cm}
\renewcommand{\arraystretch}{1.5}

\begin{document}
\onehalfspacing
\begin{table}
\sisetup{table-number-alignment=left,
tight-spacing = true}
\centering
\footnotesize
\begin{tabular}{|L{3.2cm} |
r | S[table-format = +1.3e+2] | r | R{1.1cm} |
r | S[table-format = +1.4e+2] | r | R{1.1cm} | }
\hline
& \multicolumn{4}{ c |}{\head{Max Condition Number $\mathbf{10^6}$}} \tabularnewline
\cline{2-9}