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

2 Answers 2

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

9
  • I want to avoid the white space between the last line and the black end rule, so that is not a solution
    – flp
    Commented Sep 13, 2015 at 1: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
    Commented Sep 13, 2015 at 2: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
    Commented Sep 13, 2015 at 2: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
    Commented Sep 13, 2015 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
    Commented Sep 13, 2015 at 11:56
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.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .