# Formatting tabu table

For this MWE

\documentclass[a4paper,10pt]{article}
\usepackage[utf8]{inputenc}

\RequirePackage{mathbbol}
\newcommand{\hmmax}{0}
\newcommand{\bmmax}{2}
\RequirePackage{bm}
\RequirePackage[allowlitunits]{siunitx}
\RequirePackage[usenames,dvipsnames,svgnames,table]{xcolor}
\RequirePackage{booktabs}
\RequirePackage{tabu}
\usepackage{diagbox}

\begin{document}

% \newcolumntype Z{X[c]{%
%   S[group-four-digits=true,
%   round-mode=places,
%   round-precision=2,
%   round-integer-to-decimal=true,
%   per-mode=symbol]
%   }}

\newcolumntype{Z}{S[
tight-spacing=true,
round-mode=places,
round-precision=2]}

\begin{tabu} to \textwidth {ZZZZZZ}
\toprule
\rowfont[c]\bfseries
\diagbox[width=8.5em]{method}{missing} & 0\% & 5\% & 10\% & 20\% & 50\% \\
\midrule
KNN                     & 0.0 & 0.123456    & 0.123456 & 0.123456 & 0.123456 \\
MICE                    & 0.0 & 0.123456    & 0.123456 & 0.123456 & 0.123456 \\
SimpleFill              & 0.0 & 0.123456    & 0.123456 & 0.123456 & 0.123456 \\
SoftImpute              & 0.0 & 0.123456    & 0.123456 & 0.123456 & 0.123456 \\
\bottomrule
\end{tabu}

\end{document}


I would like the table to be like this:

• the first column left aligned
• the column headers to be center aligned
• the body columns (0.123456) to be center aligned at the dot with siunitx
• the second column should be half as wide as the following columns
• the first column should be twice as wide as the later columns (and four times as wide as the second column). For that I had tried X[2] and X[0.5], but I don't manage to transfer this to the Z columns.

I tried two versions of the definition of Z, but it does not work. How do I do that?

Like this?

Edit: From given MWE I assumed, that the table had to have width of \textwidth and columns had to be in ratio 4:1:2. This can be achieved on two ways:

• superimpose column type p{<width>} to S column type. This can be done by use of \multicolumn{1}{>{\centering\arraybackslash}p{<width>}{...} for column heaser. <width> is calculated from \textwidth considering width ratio of columns (first more complicated solution) with

\newlength\colwidth <-- new length used for determining column widths \setlength\colwidth{\dimexpr0.077\linewidth-\tabcolsep+\arrayrulewidth\relax} <-- calculation of base column width

Base width is in p{<width>} multiplied according to desired ratio of columns widths

• determine S columns width with option table-column-width= where the base column width is calculated on the same way as above (second example)

First solution:

\documentclass[a4paper,10pt]{article}
\usepackage[utf8]{inputenc}

\RequirePackage{mathbbol}
\newcommand{\hmmax}{0}
\newcommand{\bmmax}{2}
\usepackage{bm}
\usepackage[allowlitunits]{siunitx}
\usepackage[usenames,dvipsnames,svgnames,table]{xcolor}
\usepackage{booktabs,tabu}
\usepackage{diagbox}

\newcolumntype{Z}{S[
%tight-spacing=true,
round-mode=places,
round-precision=2]}

\begin{document}
\noindent
\begin{tabu} to \textwidth {p{4\colwidth} *{5}{Z}}% changed
\toprule
\rowfont[c]\bfseries
\diagbox[width=4\colwidth]{method}{missing} % changed
& \mcp{1}{0\%}
&\mcp{2}{5\%} & \mcp{2}{10\%}
& \mcp{2}{20\%}
& \mcp{2}{50\%} \\ % changed
\midrule
KNN             & 0.0 & 0.123456    & 0.123456 & 0.123456 & 0.123456 \\
MICE            & 0.0 & 0.123456    & 0.123456 & 0.123456 & 0.123456 \\
SimpleFill      & 0.0 & 0.123456    & 0.123456 & 0.123456 & 0.123456 \\
SoftImpute      & 0.0 & 0.123456    & 0.123456 & 0.123456 & 0.123456 \\
\bottomrule
\end{tabu}
\end{document}


Second solution, where had not be used tabu macro \rowfont[c]\bfseries due to incompatibility with S type headers and therefore columns headers are not in bold face:

\documentclass[a4paper,10pt]{article}
\usepackage[utf8]{inputenc}

\RequirePackage{mathbbol}
\newcommand{\hmmax}{0}
\newcommand{\bmmax}{2}
\usepackage{bm}
\usepackage[allowlitunits]{siunitx}
\usepackage[usenames,dvipsnames,svgnames,table]{xcolor}
\usepackage{booktabs,tabu}
\usepackage{diagbox}

\begin{document}
\noindent
\begin{tabu} to \textwidth {X % changed
round-mode=places,
round-precision=2]}
}
\toprule
%\rowfont[c]\bfseries
\diagbox[width=4\colwidth]{method}{missing}
& \SI{0}{\%} & \SI{5}{\%}  & \SI{10}{\%} & \SI{20}{\%} & \SI{50}{\%}  \\
\midrule
KNN         &   0.0         &   0.123456    &   0.123456    &   0.123456    & 0.123456  \\
MICE        &   0.0         &   0.123456    &   0.123456    &   0.123456    & 0.123456  \\
SimpleFill  &   0.0         &   0.123456    &   0.123456    &   0.123456    & 0.123456  \\
SoftImpute  &   0.0         &   0.123456    &   0.123456    &   0.123456    & 0.123456  \\
\bottomrule
\end{tabu}
\end{document}

• I would like to change the round precision. However the column with all the 0s should still show 0.0 instead of 0.00000. Also, your code looks might complex: Can you explain it? – Make42 Mar 30 '17 at 16:58
• See edit of answer. – Zarko Mar 30 '17 at 19:23
• @Make42, is edited answer what you looking for? – Zarko Mar 31 '17 at 8:37
• To adapt your first solution with my request regarding the digits after the dot, I just defined a second column type. This worked. Your second solution does not compile: " Emergency stop" is what I get. How is your second solution an improvement compared to the first solution? Especially if the head cannot be bold in your second solution? – Make42 Mar 31 '17 at 9:07
• @Make42, for cause of second example: (i) you have different version of package (I use recent siunitx`), or (ii) you test solution in document, which very differ from MWE (example). As it is should compile without any problem (I just test it again, it works!) – Zarko Mar 31 '17 at 9:21