0

I want to create a table using cmidrule; cline does not split the line into several separate lines.

I have the following code:

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[referable]{threeparttablex}
\usepackage{caption}
\usepackage{booktabs}
\usepackage{multirow}

\begin{document}
\begin{threeparttable}
\def\sym#1{\ifmmode^{#1}\else\(^{#1}\)\fi}
\caption{Comparison between two groups}
\scalebox{0.65}{\parbox{\linewidth}{%
\begin{tabular}{l l cccc  cccc cc} \hline\hline
&& \multicolumn{4}{c}{group1}  &\multicolumn{4}{c}{group2}  & \multicolumn{2}{c}{Difference in mean} \\ 
%\cline{3-6} \cline{7-10} \cline{11-12}
\cmidrule{r}{3-6} \cmidrule{r}{7-10} \cmidrule{r}{11-12}
&& obs.&mean1&std. dev. &mean2& obs.&mean1& std. dev.&mean2& mean1 diff. & mean2. diff\\
\rowgroup{ \textbf{\textit{Panel A. }}} \\
\multirow{2}{*}{\textit{Period 1}}& var1 \\
& var2 \\
\hline
\multirow{3}{*}{\textit{Period2}}& var1 \\
& var2 \\
\hline
\multirow{2}{*}{Period 3}& var1 \\
& var2 \\
\hline
\rowgroup{\textbf{\textit{Panel B. }}} \\
\multirow{2}{*}{\textit{Period 1}}& var1 \\
& var2 \\
\hline
\multirow{3}{*}{\textit{Period2}}& var1 \\
& var2 \\
\hline
\multirow{2}{*}{Period 3}& var1 \\
& var2 \\
\hline \hline
\end{tabular}
\begin{tablenotes}[flushleft]\footnotesize 
\item[1] hello
\end{tablenotes}}}
\end{threeparttable}
\end{document}

Using cline creates a table: enter image description here

The line under the first row does not break for different groups, which is not what I wanted. But if I use cmidrule to replace the cline row:

\cmidrule{r}{3-6} \cmidrule{r}{7-10} \cmidrule{r}{11-12}

It gave me different errors when I tried to complie it multiple times. One of them is "file ended while scanning use of \@writefile."

I don't know why this happens. Is it because I am using cmidrule with multirow or multicolumn? Can anybody help? Thanks!

  • Where's your \begin{document} and incidental end? – TeXnician Feb 5 '17 at 16:48
  • 1
    It is \cmidrule(r){3-6} \cmidrule(r){7-10} \cmidrule(r){11-12} with parentheses. – AboAmmar Feb 5 '17 at 16:52
  • I forgot to type \begin{document}.. It is before \begin{threeparttable}. The \end{document} should be after the \end{threeparttable} – user123818 Feb 5 '17 at 16:57
0

Okay, your MWE is not compilable, but as far as I can see you did not correct your syntax. It works just fine, if you replace \cline{r}{1-1} with \cline(r){1-1}. A compiled example gives:

table

So here's the corrected code with \begin{document} etc.

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[referable]{threeparttablex}
\usepackage{caption}
\usepackage{booktabs}
\usepackage{multirow}
\usepackage{graphicx}

\begin{document}
\begin{threeparttable}
\def\sym#1{\ifmmode^{#1}\else\(^{#1}\)\fi}
\caption{Comparison between two groups}
\scalebox{0.65}{\parbox{\linewidth}{%
\begin{tabular}{l l cccc  cccc cc} \hline\hline
&& \multicolumn{4}{c}{group1}  &\multicolumn{4}{c}{group2}  & \multicolumn{2}{c}{Difference in mean} \\ 
%\cline{3-6} \cline{7-10} \cline{11-12}
\cmidrule(r){3-6} \cmidrule(r){7-10} \cmidrule(r){11-12}
&& obs.&mean1&std. dev. &mean2& obs.&mean1& std. dev.&mean2& mean1 diff. & mean2. diff\\
\multirow{2}{*}{\textit{Period 1}}& var1 \\
& var2 \\
\hline
\multirow{3}{*}{\textit{Period2}}& var1 \\
& var2 \\
\hline
\multirow{2}{*}{Period 3}& var1 \\
& var2 \\
\hline
\multirow{2}{*}{\textit{Period 1}}& var1 \\
& var2 \\
\hline
\multirow{3}{*}{\textit{Period2}}& var1 \\
& var2 \\
\hline
\multirow{2}{*}{Period 3}& var1 \\
& var2 \\
\hline \hline
\end{tabular}
\begin{tablenotes}[flushleft]\footnotesize 
\item[1] hello
\end{tablenotes}}}
\end{threeparttable}
\end{document}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.