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]
andX[0.5]
, but I don't manage to transfer this to theZ
columns.
I tried two versions of the definition of Z, but it does not work. How do I do that?
Best Answer
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>}
toS
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 widthBase width is in
p{<width>}
multiplied according to desired ratio of columns widthsdetermine
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:
Second solution, where had not be used
tabu
macro\rowfont[c]\bfseries
due to incompatibility withS
type headers and therefore columns headers are not in bold face: