Positioning of \% append to numbers in the last S column
This is a documented situation (siunitx
manual, section 7.13): use the low-level \cr
here:
\documentclass{article}
\usepackage{array}
\usepackage{siunitx}
\newcommand\mcp[1]{\multicolumn{1}{>{\centering\arraybackslash}p{22mm}}{\bfseries #1}}
\begin{document}
\begin{tabular}%{\linewidth}{
{ c
*{4}{S[table-format=2.2,
table-space-text-post=\,\%]<{\,\%}}
}
\hline
& \mcp{AA} & \mcp{BB} & \mcp{AA} & \mcp{BB} \cr
\hline
A1 & 0.12 & 0.12 & 0.12 & 0.12 \cr
A2 & 0.19 & 0.19 & 0.21 & 0.21 \cr
\hline
\end{tabular}
\end{document}
You can use a dummy column. I present two implementations of your table, the second one with tabular*
.
\documentclass{article}
\usepackage{array}
\usepackage{siunitx}
% use this if the headers are just one line long
%\newcommand\mcp[1]{%
% \multicolumn{1}{c}{\makebox[22mm]{\bfseries #1}}%
%}
\newcommand\mcp[1]{%
\multicolumn{1}{>{\centering}p{22mm}}{\bfseries #1}%
}
% for the second table
\newcommand{\tbh}[1]{\multicolumn{1}{c}{\bfseries #1}}
\begin{document}
\centering
\begin{tabular}{
c
*{4}{S[table-format=2.2,table-space-text-post=\,\%]<{\,\%}}
c@{}
}
\hline
& \mcp{AA} & \mcp{BB} & \mcp{AA} & \mcp{BB} & \tabularnewline
\hline
A1 & 0.12 & 0.12 & 0.12 & 0.12 & \\[2ex]
A2 & 0.19 & 0.19 & 0.21 & 0.21 & \\
\hline
\end{tabular}
\bigskip
\begin{tabular*}{\textwidth}{
@{\hspace{\tabcolsep}\extracolsep{\fill}}
c
*{4}{S[table-format=2.2,table-space-text-post=\,\%]<{\,\%}}
@{\extracolsep{0pt}}c@{\hspace{\tabcolsep}}
}
\hline
& \tbh{AA} & \tbh{BB} & \tbh{AA} & \tbh{BB} & \\
\hline
A1 & 0.12 & 0.12 & 0.12 & 0.12 & \\[2ex]
A2 & 0.19 & 0.19 & 0.21 & 0.21 & \\
\hline
\end{tabular*}
\end{document}