2

I have several tables in the following custom format, to which I would like to add vertical space (e.g. 6 pt) after every second row. I know this can be done manually. I am only wondering, if there is a process to do this faster. Note that my tables come from external tex.files. So if possible I'd like a solution which can be applied to tables imported via input (source: xtable/R). But I am also curious how to do this quickly for normally, in Latex produced tables.

Here is a simple MWE:

\documentclass[a4paper, 12pt, headsepline, smallheadings]{scrreprt}
\usepackage{dcolumn}
\usepackage{booktabs}
\usepackage[a4paper]{geometry}
\newcolumntype{Y}{D..{-1}}
\geometry{left=2cm,right=5cm,top=2cm,bottom=2cm}

\begin{document}
\begin{table}[htbp]
\centering
\caption{aaa} 
{\normalsize
\begin{tabular}{lYYYYY}
\toprule 
& \multicolumn{1}{r}{A} & \multicolumn{1}{c}{B} & 
\multicolumn{1}{c}{C} & \multicolumn{1}{c}{E} &
\multicolumn{1}{c}{D} \\
\midrule 
\multicolumn{1}{l}{X} &  0.34  &  0.08^{***} & -2.57^{***} &  0.60^{***} &  80.97 \\ 
& (0.44) & (0.05) & (1.26) & (0.24) &  \\ 
\multicolumn{1}{l}{Y} &  0.34  &  0.20^{***} &  0.99^{***} &  0.00^{***}   & 97.71 \\ 
& (1.30) & (1.03) & (0.01) & (0.00) &  \\ 
\multicolumn{1}{l}{Z} &  0.56  & 5.41^{***} &  0.08^{***} &  0.98^{***} & 33.27 \\ 
& (1.30) & (2.030) & (0.03) & (0.01) &  \\ 
\bottomrule 
\end{tabular}
}
\end{table}
\end{document}

So in the end, I want this table to look as good as possible. Any suggestions appreciated, except for the content/brackets/stars. These must stay. Thanks.

3

I don't know if there's a good way to do this, so I'll suggest a hack and possibly not a particularly good one. The trick is to alternately replace \\ with \crsng and \crdbl. The former is just equivalent to your old \\ and the latter is equivalent to your old \\[6pt].

  1. Introduce the following before \begin{tabular}:

    \global\let\restorecr=\
    
  2. Introduce the following after \toprule:

    \global\let\oldcr=\\
    \global\def\crsng{\global\let\\=\crdbl\oldcr}
    \global\def\crdbl{\global\let\\=\crsng\oldcr[6pt]}
    \global\let\\=\crdbl
    
  3. Introduce the following after \end{tabular}:

    \global\let\\=\restorecr
    

You'll probably want to tweak it a little bit, if you don't like what it's doing to the header and the footer of your tabular.

result

  • thanks for the hack. I am waiting a little bit more to see if someone has a different approach, then I'd accept your answer. It doesn't work with external tex files though. – TomM Dec 8 '13 at 16:31
  • You mean if you \input what's inside your tabular? I can't understand why it shouldn't work. – nickie Dec 8 '13 at 20:37
  • I believe it does work, but Texstudio shows errors if you do it that way. It seems to think the part in input is missing. I am leaving this open a little bit, maybe someone has a different solution. But eventually you will get the accept if nothing else shows up in the near future. – TomM Dec 8 '13 at 23:09

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.