# How to remove the space after \midrule in a table

I have a table with color in the rows. When the first or last column is colored as shown below, there is an ugly white space before or after the cell. I want to remove this white space (in this picture, it only appears in the first row as it is the colored one. But the same thing applies when the last row is colored. I do not want this space in both the first and last rows).

Here is the script:

%README: this copy with comprehensive attack and defences description.

\documentclass[compsoc, conference, letterpaper, 10pt, times]{IEEEtran}
\ifCLASSOPTIONcompsoc
% IEEE Computer Society needs nocompress option
% requires cite.sty v4.0 or later (November 2003)
\usepackage[nocompress]{cite}
\else
% normal IEEE

\usepackage{cite}
\fi
\ifCLASSINFOpdf
\else
\fi

\usepackage{colortbl}
\usepackage{array}
\usepackage{booktabs}
\usepackage{multirow}
\newcommand{\normal}[1]{\multicolumn{1}{l}{#1}}
\usepackage{amssymb}% http://ctan.org/pkg/amssymb
\usepackage{pifont}% http://ctan.org/pkg/pifont
\newcommand{\cmark}{\ding{51}}%
\newcommand{\xmark}{\ding{55}}%
\newcommand*\rot{\rotatebox{90}}
\usepackage{tabularx}

\usepackage{msc}
\usepackage{xcolor}
\newcommand{\quotes}[1]{#1''} %for qoutation marks

\DeclareRobustCommand*{\IEEEauthorrefmark}[1]{%
\raisebox{0pt}[0pt][0pt]{\textsuperscript{\footnotesize\ensuremath{#1}}}}

\begin{document}
\title{Test}

\maketitle

\begin{table}
\caption{mytable}
\label{table:mytable}

\begin{tabular}{ l *{45}{c} }

\toprule
&   \multicolumn{3}{c}{B} \\
\cmidrule(lr){2-4}
\multicolumn{1}{c}{\multirow{-2}{*}[0.5ex]{A}}
&   AAA & BBB & CCC \\
\midrule
\rowcolor[gray]{.9}
Text1 &   \cmark & \cmark & \cmark \\
Text2 &   \xmark & \cmark & \xmark \\
\rowcolor[gray]{.9}
Text3 &   \cmark & \xmark & \xmark \\
Text4 &   \cmark & \cmark & \cmark \\
\bottomrule
\end{tabular}
\end{table}
\end{document}


The spacing can be adjusted using \aboverulesep = 0.605mm (adjusts the separation above all kinds of rules except the top one and it has a default value of 0.4ex or 0.605mm) and \belowrulesep = 0.984mm (adjusts the separation below all kinds of rules except the bottom one and it has a default value of 0.65ex or 0.984mm).


%README: this copy with comprehensive attack and defences description.

\documentclass[compsoc, conference, letterpaper, 10pt, times]{IEEEtran}
\ifCLASSOPTIONcompsoc
% IEEE Computer Society needs nocompress option
% requires cite.sty v4.0 or later (November 2003)
\usepackage[nocompress]{cite}
\else
% normal IEEE

\usepackage{cite}
\fi
\ifCLASSINFOpdf
\else
\fi

\usepackage{colortbl}
\usepackage{array}
\usepackage{booktabs}

% The new commands
\newcommand{\midsepremove}{\aboverulesep = 0mm \belowrulesep = 0mm}
\midsepremove
\newcommand{\midsepdefault}{\aboverulesep = 0.605mm \belowrulesep = 0.984mm}
\midsepdefault

\usepackage{caption}
\captionsetup{justification=centering}

\usepackage{multirow}
\newcommand{\normal}[1]{\multicolumn{1}{l}{#1}}
\usepackage{amssymb}% http://ctan.org/pkg/amssymb
\usepackage{pifont}% http://ctan.org/pkg/pifont
\newcommand{\cmark}{\ding{51}}%
\newcommand{\xmark}{\ding{55}}%
\newcommand*\rot{\rotatebox{90}}
\usepackage{tabularx}

\usepackage{msc}
\usepackage{xcolor}
\newcommand{\quotes}[1]{#1''} %for qoutation marks

\DeclareRobustCommand*{\IEEEauthorrefmark}[1]{%
\raisebox{0pt}[0pt][0pt]{\textsuperscript{\footnotesize\ensuremath{#1}}}}

\begin{document}
\title{Test}

\maketitle

\begin{table}
\caption{mytable}
\label{table:mytable}
\centering

\midsepremove
\begin{tabular}{ l *{45}{c} }

\toprule
&   \multicolumn{3}{c}{B} \\
\cmidrule(lr){2-4}
\multicolumn{1}{c}{\multirow{-2}{*}[0.5ex]{A}}
&   AAA & BBB & CCC \\
\midrule
\rowcolor[gray]{.9}
Text1 &   \cmark & \cmark & \cmark \\
Text2 &   \xmark & \cmark & \xmark \\
\rowcolor[gray]{.9}
Text3 &   \cmark & \xmark & \xmark \\
Text4 &   \cmark & \cmark & \cmark \\
\bottomrule
\end{tabular}
\midsepdefault

\end{table}
\end{document}


Off-topic: use \centering to center the table below the caption. Also, use \captionsetup{justification=centering} for better handling of floats caption positions.

• Are you sure your suggestions will be acceptable to the conference or journal to which the OP is submitting? – cfr Jul 22 '17 at 2:31
• Don't use mm for the \aboveruleseps. In \midsepdefault you should use 0.4ex and 0.65ex for the one below. There is a reason why these are in ex and not in mm or another absolute measurement. – Skillmon Jul 22 '17 at 6:16
• @cfr Yes, modify columns separation is acceptable if it makes the document more readable. The editor will make the final decisions on how the format will be if the paper is accepted. – Al-Motasem Aldaoudeyeh Jul 22 '17 at 6:54
• @Skillmon. Why shouldn't we use mm here? – Al-Motasem Aldaoudeyeh Jul 22 '17 at 6:56
• @Al-MotasemAldaoudeyeh because \aboverulesep is 1.8067pt without your redefinition to 0.605mm and 1.72137pt with it. Well maybe you shouldn't use ex in your command either (because if it's called in a surrounding of different font size, the width is wrong either). You might use mm, but then use the correct value. – Skillmon Jul 22 '17 at 7:04

You can change \midrule by something like \specialrule{.4pt}{2pt}{0pt} and the \bottomrule by \specialrule{.8pt}{0pt}{2pt}

• I think you should use \heavyrulewidth for the width of the \bottomrule and \lightrulewidth for \midrule to ensure a uniform look. – Skillmon Jul 21 '17 at 22:51
• @Skillmon, uhmm...yes, if you change \heavyrulewidth length or you can distinguish 0.8pt of the default (0.80301pt). – Fran Jul 21 '17 at 23:00
• @Fran can you post the modified script please? – user6875880 Jul 21 '17 at 23:19
• @user6875880 Why? Is just replace both commands in your own example, nothing too tricky. – Fran Jul 22 '17 at 9:37

With use of cellspace package for adding S attribute to columns type and settings above and below booktabs' rules space to zero:

\documentclass[compsoc, conference, letterpaper, 10pt, times]{IEEEtran}

\usepackage{pifont}
\newcommand{\cmark}{\ding{51}}%
\newcommand{\xmark}{\ding{55}}%

\usepackage[table]{xcolor}
\usepackage{booktabs, cellspace, multirow}
\setlength\aboverulesep{0pt}
\setlength\belowrulesep{0pt}
\setlength\cellspacetoplimit{3pt}
\setlength\cellspacebottomlimit{3pt}

\begin{document}
\begin{table}
\centering
\caption{Table title}
\label{tab:my important table}
\rowcolors{2}{}{gray!20}
\begin{tabular}{ l *{4}{Sc} }
\toprule
&   \multicolumn{3}{Sc}{B} \\
\cmidrule(lr){2-4}
\multicolumn{1}{c}{\multirow{-2}{*}[1.5pt]{A}}
&   AAA & BBB & CCC \\
\midrule
Text1 &   \cmark & \cmark & \cmark \\
Text2 &   \xmark & \cmark & \xmark \\
Text3 &   \cmark & \xmark & \xmark \\
Text4 &   \cmark & \cmark & \cmark \\
\bottomrule
\end{tabular}
\end{table}
\end{document}


When using tabularx (for whatever reason), I found this solution useful:

\documentclass{article}
\usepackage[table]{xcolor}
\usepackage{tabularx, booktabs}

\newcommand{\midruletop}{\specialrule{\lightrulewidth}{\aboverulesep}{0em}}
\newcommand{\midrulebottom}{\specialrule{\lightrulewidth}{0em}{\belowrulesep}}
\newcommand{\vertsp}{{\Large$\phantom{\mid}$\hspace{-.25em}}}
\newcommand{\hlrow}{\rowcolor{lightgray}\vertsp}
\newcommand{\hlcell}{\cellcolor{lightgray}\vertsp}

\begin{document}
\begin{tabularx}{.5\columnwidth}{XX}
\toprule
\textbf{A} & \textbf{B}
\\\midruletop
\multicolumn{2}{l}{\hlcell a}
\\\midrulebottom
a & b
\\\midruletop
\hlrow a & b
\\\midrulebottom
\end{tabularx}
\end{document}


For highlighting the last line, create a new command from \midrulebottom using \heavyrulewidth.

Note that the cellspace manual suggests that it might also work with tabularx. I didn't try, though.

If you want to keep the exact positions of the rules drawn with booktabs and to color rows with respect to these rules, you may use nicematrix (4.0+). You need several compilations.

\documentclass{article}

\usepackage{nicematrix}
\usepackage{booktabs}
\usepackage{pifont}

\newcommand{\cmark}{\ding{51}}
\newcommand{\xmark}{\ding{55}}

\begin{document}

\begin{NiceTabular}{LCCC}[code-before = \rowcolors[gray]{3}{0.9}{}]
\toprule
\Block{2-1}{A} &  & B & \\
\cmidrule{2-4}
& AAA & BBB & CCC \\
\midrule
Text1 & \cmark & \cmark & \cmark \\
Text2 & \xmark & \cmark & \xmark \\
Text3 & \xmark & \xmark & \xmark \\
Text4 & \cmark & \cmark & \cmark \\
\bottomrule
\end{NiceTabular}

\end{document}


• In this answer, since version 5.0 of nicematrix one must write lccc instead of LCCC in the preamble of {NiceTabular} (but there is an option for backward compatibility). – F. Pantigny Jul 18 at 20:48