2

I tried to remove the white space between the last row and the top/bottomrule and I already found some solutions but I couldn't get them work:

Table Row Color Covers Text

Combining \rowcolor and \cmidrule

The only way I could get that working was by the following example because the direct application of the above linked code resulted in an missing noalign:

\documentclass[a4paper, 12pt]{article}
\usepackage[table]{xcolor}
\usepackage{longtable}
\usepackage{booktabs}
\definecolor{hellgrau}{gray}{0.9}
\newcommand{\ra}[1]{\renewcommand{\arraystretch}{#1}}

\ra{1.3}
\begin{document}
\begin{longtable}{>{\kern-\tabcolsep}lll<{\kern-\tabcolsep}}
\toprule
A & B & C \\
\midrule
\endhead
A & B & C \\
\rowcolor{hellgrau}
A & B & C \\
A & B & C \\
\rowcolor{hellgrau}
A & B & C\\
\specialrule{0.08em}{0pt}{-0.08em}
\arrayrulecolor{black}\\
\caption{Caption}
\label{tab:table}
\end{longtable}
\end{document}

On the downside that duplicates the distance of the caption and looks really disgusting so that I cannot consider this as solution.

Result

flp
  • 459

2 Answers2

1

Like that? With longtable, the caption must be written inside the table. Btw, traditionally, table captions are placed above the table (while figure captions are plced below the figure).

\documentclass[a4paper, 12pt]{article}
\usepackage[table]{xcolor}
\usepackage{longtable}
\usepackage{booktabs}
\definecolor{rowgray}{gray}{0.9}
\newcommand{\ra}[1]{\renewcommand{\arraystretch}{#1}}
\ra{1.3}

\begin{document}

\begin{longtable}{>{\kern-\tabcolsep}lll<{\kern-\tabcolsep}}
  \toprule
  A & B & C \\
  \midrule
  \endhead
  \bottomrule\addlinespace[\belowrulesep]
  \arrayrulecolor{black}%\\
  \caption{Caption}
  \label{tab:table}
  \endlastfoot
  A & B & C \\
  \rowcolor{rowgray}
  A & B & C \\
  A & B & C \\
  \rowcolor{rowgray}
  A & B & C \vspace{-\aboverulesep}
\end{longtable}

\end{document} 

enter image description here

Bernard
  • 271,350
  • I want to avoid the white space between the last line and the black end rule, so that is not a solution – flp Sep 13 '15 at 01:55
  • That is a problem between booktabs and colortbl, due to the padding booktabs adds to the rules. That is why I proposed a solution with cellspace, which consists more or less in emulating what booktabs does without this drawback. – Bernard Sep 13 '15 at 02:01
  • Finally, I've a work-around: addind a suitable negative \space at the end of the last row. See my modified answer if it's OK now. – Bernard Sep 13 '15 at 02:07
  • Hm, many solutions work for my simple example, but they do not apply to my real table because also with your solution I always get a Misplaced \noalign. \caption error. Therefore I included my real table, because I assume I located the error in the wrong place – flp Sep 13 '15 at 11:50
  • Seems to be a big problem with my latex file because even my real sample could be simply fixed. Therefore, I really located the error wrongly – flp Sep 13 '15 at 11:56
  • Where did you include the real table? – Bernard Sep 13 '15 at 11:56
  • Nowhere, as I figured out now its an underlying problem of my config file. I will do further investigation and hope I can fix the problem. – flp Sep 13 '15 at 11:59
  • I found the problem: \usepackage{arydshln} although never used somehow created this Misplaced \noalign. \caption. Without the package, both, your and my initial solution do work. Thanks for your help :) – flp Sep 13 '15 at 12:04
  • You're welcome. Always glad to help! – Bernard Sep 13 '15 at 12:06
0

The underlying problem was totally wrong located by me. The Misplaced \noalign. \caption error was caused by the included \usepackage{arydshln} which I never used anymore so I didn't assume the error to be caused there. Otherwise, both my initial solution as well as @Bernard's solution work fine.

flp
  • 459