5

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}
\usepackage[showframe,top=2.5cm, left=3.5cm, bottom=2.5cm, right=2.5cm, includehead]{geometry}
\geometry{headheight=28pt, headsep=18pt}

% 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}}

\newcommand{\head}[1]{\centering\textbf{#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}  
 \head{Method and Details}   & \head{NCh}   & \head{Condition Number} & \head{DFS} & \head{DFS\newline per chan}  & \head{NCh} & \head{Condition Number} & \head{DFS} & \head{DFS\newline per chan} \tabularnewline [0.5ex]
  \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] 
  % [1ex] adds vertical space

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

\end{table}


\end{document}

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

table

2 Answers 2

5

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,
  includehead,
  headheight=28pt,
  headsep=18pt,
  showframe,
}

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

\newcommand{\head}[1]{%
  \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
\addtolength{\tabcolsep}{-0.6pt}
\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
\multicolumn{1}{c}{\head{Method and \\ Details}} &
  \head{NCh} & \head{Condition \\ Number} & \head{DFS} & \head{DFS \\ per \\ chan} &
  \head{NCh} & \head{Condition \\ Number} & \head{DFS} & \head{DFS \\ per \\ chan} \\
\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}

enter image description here

3
  • 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, 2014 at 15:52
  • One quick question: best to check, presumably the change to tabcolsep remains within this table environment?
    – FionaSmith
    May 23, 2014 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, 2014 at 15:55
3

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.

enter image description here

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

% Page geometry etc
\usepackage{setspace} % allow different line spacing
\renewcommand{\topfraction}{0.85}
\renewcommand{\textfraction}{0.1}
\usepackage[showframe,top=2.5cm, left=3.5cm, bottom=2.5cm, right=2.5cm, includehead]{geometry}
\geometry{headheight=28pt, headsep=18pt}

\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}}

\newcommand{\head}[1]{\centering\textbf{#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{Full Selection}} 
  & \multicolumn{4}{ c |}{\head{Max Condition Number $\mathbf{10^6}$}} \tabularnewline  
  \cline{2-9}
  \head{Method and Details}   & 
  \head{NCh} & \multicolumn{1}{R{2.0cm}|}{\head{Condition Number}} & \head{DFS} & \head{DFS\newline per chan}  &
  \head{NCh} & \multicolumn{1}{R{2.0cm}|}{\head{Condition Number}} & \head{DFS} & \head{DFS\newline per chan} \tabularnewline [0.5ex]
  \hline
  \textbf{1:}  &     210 & 0.496e07 &  84.3  &   0.40   &    153 &     0.8126E+06 &  69.3   &   0.45 \\
  \textbf{2:}  8 Clear 1.3 WVE       &     183 & 0.130E11 & 207.1  &   1.13   &     76 &   0.9469E6 &  91.5   &   1.20 \\ [1ex]
  % [1ex] adds vertical space
  \hline
  \end{tabular}
  \caption{caption }
\end{table}
\end{document}
1
  • Thanks for taking the time to answer. It's very useful to know that.
    – FionaSmith
    May 23, 2014 at 16:10

You must log in to answer this question.

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