I am having troubles (again) with a table in tabularx
where I would like to have fixed width for columns 2 to 5 and a table which is wide as the text block.
I also have a problem with the text in the first cell (multirow
), which is not vertically centered.
The code I have so far is:
\documentclass[12pt, oneside]{article}
\usepackage{multicol}
\usepackage{multirow}
\usepackage{tabularx}
\usepackage{siunitx}
\usepackage{booktabs}
\renewcommand{\arraystretch}{1.3}
\setlength{\tabcolsep}{5pt}
\usepackage{caption}
\captionsetup[table]{skip=5pt}
\newcolumntype{x}[1]{>{\centering\arraybackslash\hspace{0pt}}p{#1}}
\begin{document}
\begin{table}
\caption{\label{Table}Indices}
\begin{tabularx}{\textwidth}{l c c @{\extracolsep{8pt}} c c}
\toprule
\multirow{2}{*}{\textbf{\textit{Index}}} & \multicolumn{2}{c}{\textbf{\textit{Method 1}}} & \multicolumn{2}{c}{\textbf{\textit{Method 2}}} \\
\cmidrule{2-3}\cmidrule{4-5}
& {\textbf{\textit{AA}}} & \textbf{\textit{BB}} & {\textbf{\textit{AA}}} & \textbf{\textit{BB}} \\
\midrule
A1 & 0.12\% & 0.12\% & 0.12\% & 0.12\% \\ \medskip\smallskip
A2 & 0.19\% & 0.19\% & 0.21\% & 0.21\% \\
B1 & 0.06\% & 0.06\% & 0.06\% & 0.06\% \\
B2 & 0.14\% & 0.14\% & 0.14\% & 0.14\% \\ \medskip\smallskip
B3 & 98.51\% & 98.53\% & 98.51\% & 98.46\% \\
C1 & 0.84\% & 0.83\% & 0.85\% & 0.84\% \\
C2 & 0.70\% & 0.70\% & 0.71\% & 0.71\% \\
C3 & 0.66\% & 0.66\% & 0.67\% & 0.67\% \\
C4 & 0.61\% & 0.61\% & 0.62\% & 0.61\% \\
\bottomrule
\end{tabularx}
\end{table}
\end{document}
Obtaining the following results:
I tried also using simple \tabular
environment, but I have problems with the @{\extracolsep{8pt}}
and I do not think it is the most correct way to handle this problem.
Please note this is a table in a big document, which is separated in chapters and many packages are used for different needs. The style of the table should also remain the same to be consistent with the rest of the document.
Thanks a lot!
EDIT
I think I am getting closer using tabular environment:
\begin{document}
\begin{table}
\caption{\label{Table}Indices}
\begin{tabular}{m{3.50cm} x{2.3cm} x{2.3cm} @{\extracolsep{8pt}} x{2.3cm} x{2.3cm}}
\toprule
\multirow{2}{*}{\textbf{\textit{Index}}} & \multicolumn{2}{c}{\textbf{\textit{Method 1}}} & \multicolumn{2}{c}{\textbf{\textit{Method 2}}} \\
\cmidrule{2-3}\cmidrule{4-5}
& {\textbf{\textit{AA}}} & \textbf{\textit{BB}} & {\textbf{\textit{AA}}} & \textbf{\textit{BB}} \\
\midrule
A1sometext here & 0.12\% & 0.12\% & 0.12\% & 0.12\% \\
A2 & 0.19\% & 0.19\% & 0.21\% & 0.21\% \\ \medskip\smallskip
B1 & 0.06\% & 0.06\% & 0.06\% & 0.06\% \\
B2 & 0.14\% & 0.14\% & 0.14\% & 0.14\% \\
B3 & 98.51\% & 98.53\% & 98.51\% & 98.46\% \\ \medskip\smallskip
C1 & 0.84\% & 0.83\% & 0.85\% & 0.84\% \\
C2 & 0.70\% & 0.70\% & 0.71\% & 0.71\% \\
C3 & 0.66\% & 0.66\% & 0.67\% & 0.67\% \\
C4 & 0.61\% & 0.61\% & 0.62\% & 0.61\% \\
\bottomrule
\end{tabular}
\end{table}
\end{document}
Still I have the problem with the vertical centering of the first cell and the space between the rows (A2 to B1 and B3 to C1).
Best Answer
You are loading
siunitx
but not using it to align the table columns which makes the98.xx
entries look out of line.I show first with
tabular
, if you really want to distort the table to full width usetabular*
but the main effect of that is to make the table harder to read.