3

I have the following code to put an extra space (a carriage return) after every second row. How can I edit the code to put the extra space after every third row instead?

\documentclass[12pt]{article}

\usepackage{booktabs}
\usepackage{dcolumn}

\begin{document}
\begin{table}

\begin{tabular*}{1\textwidth}{@{
\global\let\restorecr=\\ 
\extracolsep{\fill} } c *{4}{c}}
\toprule

\global\let\oldcr=\\ 
\global\def\crsng{\global\let\\ =\crdbl\oldcr}
\global\def\crdbl{\global\let\\ =\crsng\oldcr[40pt]}
\global\let\\=\crdbl

& \multicolumn{4}{c}{\textbf{Panel A}}\\ 
\midrule
a & 0.55 & 0.66 & 0.64 & 0.64 \\
  & 0.55 & 0.66 & 0.64 & 0.64 \\ 
  & 0.55 & 0.66 & 0.64 & 0.64 \\
a & 0.55 & 0.66 & 0.64 & 0.64 \\ 
  & 0.55 & 0.66 & 0.64 & 0.64 \\
  & 0.55 & 0.66 & 0.64 & 0.64 \\ 
\bottomrule
\end{tabular*}
\global\let\\ =\restorecr

\end{table}

\end{document}

EDIT: If I add more panels of data the solution proposed below no longer works.

&\multicolumn{4}{c}{\textbf{All Data}}\tabularnewline     
& \multicolumn{4}{c}{\textbf{Panel A}}\tabularnewline 
\midrule
a & 0.55 & 0.66 & 0.64 & 0.64 \\
  & 0.55 & 0.66 & 0.64 & 0.64 \\ 
  & 0.55 & 0.66 & 0.64 & 0.64 \\
a & 0.55 & 0.66 & 0.64 & 0.64 \\ 
a & 0.55 & 0.66 & 0.64 & 0.64 \\
  & 0.55 & 0.66 & 0.64 & 0.64 \\ 
    & \multicolumn{4}{c}{\textbf{Panel B}}\tabularnewline
\midrule
a & 0.55 & 0.66 & 0.64 & 0.64 \\
  & 0.55 & 0.66 & 0.64 & 0.64 \\ 
  & 0.55 & 0.66 & 0.64 & 0.64 \\
a & 0.55 & 0.66 & 0.64 & 0.64 \\ 
a & 0.55 & 0.66 & 0.64 & 0.64 \\
  & 0.55 & 0.66 & 0.64 & 0.64 \\ 
    & \multicolumn{4}{c}{\textbf{Panel C}}\tabularnewline 
\midrule
a & 0.55 & 0.66 & 0.64 & 0.64 \\
  & 0.55 & 0.66 & 0.64 & 0.64 \\ 
  & 0.55 & 0.66 & 0.64 & 0.64 \\
a & 0.55 & 0.66 & 0.64 & 0.64 \\ 
a & 0.55 & 0.66 & 0.64 & 0.64 \\
  & 0.55 & 0.66 & 0.64 & 0.64 \\ 
2
  • 1
    Note that \global\let\\=\restorecr is a mistake, because \\ has different meanings inside a tabular than outside.
    – egreg
    Nov 11, 2014 at 13:18
  • 1
    It seems that a workaround for this new edit is to replace the second \tabularnewline at top with \vspace{-1.5cm}\\. Then the result will show what you want.
    – Jesse
    Nov 11, 2014 at 14:59

1 Answer 1

1

This solution does not understand the mechanism behind the code (not up to par anyway), but based on the given code for inserting vertical space for every second row, this solution found the logic behind it and this is how this solution is generated here.

enter image description here

Code

\documentclass[12pt]{article}

\usepackage{booktabs}
\usepackage{dcolumn}

\begin{document}
\begin{table}

\begin{tabular*}{1\textwidth}{@{
\global\let\restorecr=\\ 
\extracolsep{\fill} } c *{4}{c}}
\toprule

%\global\let\oldcr=\\ 
%\global\def\crsng{\global\let\\ =\crdbl\oldcr}
%\global\def\crdbl{\global\let\\ =\crsng\oldcr[40pt]}
%\global\let\\=\crdbl

\global\let\oldcr=\\ 
\global\def\crsng{\global\let\\ =\crtri\oldcr}
\global\def\crdbl{\global\let\\ =\crsng\oldcr}
\global\def\crtri{\global\let\\ =\crdbl\oldcr[40pt]}
\global\let\\=\crtri

& \multicolumn{4}{c}{\textbf{Panel A}}\\ 
\midrule
a & 0.55 & 0.66 & 0.64 & 0.64 \\
  & 0.55 & 0.66 & 0.64 & 0.64 \\ 
  & 0.55 & 0.66 & 0.64 & 0.64 \\
a & 0.55 & 0.66 & 0.64 & 0.64 \\ 
  & 0.55 & 0.66 & 0.64 & 0.64 \\
  & 0.55 & 0.66 & 0.64 & 0.64 \\ 
\bottomrule
\end{tabular*}
\global\let\\ =\restorecr

\end{table}
2
  • That solution is helpful, but is there any way to avoid the pattern of spacing every three lines being applied to the `& \multicolumn{4}{c}{\textbf{Panel A}}\\' statement? I want to apply it only to every third row in each panel. I'll add an edit to the question. Nov 11, 2014 at 14:21
  • 1
    I tried \vspace{-1.5cm} right before \multicolumn can reduce the gap.
    – Jesse
    Nov 11, 2014 at 14:40

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.