# Line not equal length in table using cmidrule (tabularx)

I found that the line is not the equal length in second row and the first row. Is it possible to make it same line length.

\documentclass{article}
\usepackage{tabularx, caption}           % Load package caption for decent foramtting and spacing
\usepackage{booktabs, ragged2e}       % Use booktabs rules and get rid og vertical rules, ragged2e to ragged text
\setlength\extrarowheight{1pt}          % Both line necessary for decent spacing, unless you are using booktabs rules.
\renewcommand{\arraystretch}{1.2}

\begin{document}

\newcolumntype{A}{>{\RaggedRight\arraybackslash\hsize=0\hsize\linewidth=\hsize}X}
\newcolumntype{B}{>{\RaggedRight\arraybackslash\hsize=0.65\hsize\linewidth=\hsize}X}
\begin{table}[!ht]

\begin{tabularx}{\textwidth}{@{}A*{5}{B}@{}}
\toprule
& & \multicolumn{3}{c}{\textbf{ATest Combination}} \\
\cmidrule(lr){3-5}
& & \small Mean (\%)
& \small Std. Deviation (\%)& \small Std. Error Mean(\%) \\
\midrule
\multicolumn{1}{l}{Pair 1} & Transpor Example Dataset (AA) - Transpor Example Dataset (BB)
& 312314.20\% & 321321.36\% & 4.321354\%  \\
\bottomrule
\end{tabularx}
\label{tab:test123}%
}
\end{table}

\end{document}


The outcome:

And also, how to make the outcome of the word in whole words without being break out automaticall using '-'?

For example:

Transpor Example
Dataset (AA) -
Transpor Example
Dataset (BB)


and not

Transpor Exam-
ple Data -
set (AA) -
Trans-
por Example
Dataset (BB)

• Regarding the horizontal line: replace \cmidrule(lr){3-5} with \cmidrule(l){3-5} or (\cmidrule{3-5}) – leandriis Aug 6 '19 at 19:11
• @leandriis, thanks. It works. Between, what is the meaning of lr and l in this part? Any source for reading this, cannot find it. – aan Aug 6 '19 at 19:14
• r = shorten the line on the right, l= shorten the line on the left. This is especially useful if you have more than one cmidrule next to each other. Without the lr two adjacent cmidrules would appear as one line instead of two. For a more in depth description, please see page 4 of the booktabs manual. – leandriis Aug 6 '19 at 19:16
• Could you please expllain the purpose of the A type column in your table? – leandriis Aug 6 '19 at 19:20
• Regarding the meaning of {@{}A*{5}{B}@{}} you might want to hava a look at: What is the use of @{}?, Repeating the same column type, Table layout with tabularx (column widths: 50%|25%|25%) and How does the \newcolumntype command work? – leandriis Aug 6 '19 at 19:39

Here are three different versions of your table:

In all of the following example, I have corrected the trimming commands of the cmidrule command ((lr), (l), (r), For a detailed explanation please see page 4 of the booktabs manual.)

In the first example, I have also replaced the column specifiers {@{}A*{5}{B}@{}} by the more reasonable {l>{\raggedright\arraybackslash}Xccc}.

In the second table, I have alternatively used S type columns from the siunitx package in order to allow the numbers to be centered with respect to their decimal separator. Additionally, I have removed repeated % signs that are superfluous since they are already mentioned in the column headers.

In the last example, I have used a slightly smaller font size and decreased the horizontal white space between adjacent columns. With this, the contents of the second column can even fit into two lines instead of 4.

\documentclass{article}
\usepackage{tabularx, caption}
\usepackage{booktabs, ragged2e}

\usepackage{makecell,siunitx}

\begin{document}

\begin{table}

\begin{tabularx}{\textwidth}{l>{\raggedright\arraybackslash}Xccc}
\toprule
& & \multicolumn{3}{c}{\textbf{ATest Combination}} \\
\cmidrule{3-5}
& & \small Mean (\%)
& \makecell{\small Std. Deviation\\ (\%)}& \makecell{\small Std. Error \\ Mean (\%)} \\
\midrule
\multicolumn{1}{l}{Pair 1} & Transpor Example Dataset (AA) - Transpor Example Dataset (BB)
& 312314.20\% & 321321.36\% & 4.321354\%  \\
\bottomrule
\end{tabularx}
\label{tab:test123}%
}
\end{table}

\begin{table}
\begin{tabularx}{\textwidth}{l>{\raggedright\arraybackslash}XS[table-format=6.2]S[table-format=6.2]S[table-format=1.6]}
\toprule
& & \multicolumn{3}{c}{ATest Combination} \\
\cmidrule{3-5}
& &  {Mean (\%)}
& {\makecell{ Std. Deviation\\ (\%)}}& {\makecell{ Std. Error \\ Mean (\%)}} \\
\midrule
\multicolumn{1}{l}{Pair 1} & Transpor Example Dataset (AA) - Transpor Example Dataset (BB)
& 312314.20 & 321321.36 & 4.321354  \\
\bottomrule
\end{tabularx}
\label{tab:test123}%
}
\end{table}

\begin{table}
\small \setlength{\tabcolsep}{3.5pt}
\begin{tabularx}{\textwidth}{l>{\raggedright\arraybackslash}Xccc}
\toprule
& & \multicolumn{3}{c}{ATest Combination} \\
\cmidrule{3-5}
& &  Mean (\%)
& \makecell{ Std. Deviation\\ (\%)}& \makecell{ Std. Error \\ Mean (\%)} \\
\midrule
\multicolumn{1}{l}{Pair 1} & Transpor Example Dataset (AA) - Transpor Example Dataset (BB)
& 312314.20 & 321321.36 & 4.321354  \\
\bottomrule
\end{tabularx}

• thanks. It is possible to bold the words in first 2 example? & \makecell{\small Std. Deviation\\ (\%)}& \makecell{\small Std. Error \\ Mean (\%)} \ . I had tried to & \makecell{\small {\textbf{std. Deviation}}\\ \{\textbf{(\%)}}& \makecell{\small {\textbf{Std. Error}}} \\ {\textbf{Mean (\%)}} \ .But it seemed not working. – aan Aug 6 '19 at 20:30
• @aan, in table you shpuld instead \makecell use \thead and in preamble define \renewcommand\theadfont{\small}. – Zarko Aug 6 '19 at 21:06
• @Zarko, thanks. Is it means that we created a new command name \thead OR put \small into \threadfont? – aan Aug 6 '19 at 21:21
• @ann: No, the \theadcommand is defined by the makecell package (intended for columns heads), as it is \makecell command. – Zarko Aug 6 '19 at 21:30