15

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).

enter image description here

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{\head}[1]{\textnormal{\textbf{#1}}}
\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}
11

enter image description here

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).

If you need to remove the separation frequently you can define \newcommand{\midsepremove}{\aboverulesep = 0mm \belowrulesep = 0mm} and \newcommand{\midsepdefault}{\aboverulesep = 0.605mm \belowrulesep = 0.984mm} to remove spacing and reset it to the default value. Before tabular environment use \midsepremove and after it use \midsepdefault. This helps reset the spacing to the default values and avoid crowded lines in normal tables.

%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{\head}[1]{\textnormal{\textbf{#1}}}
\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
9

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

mwe

  • 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
  • 1
    @user6875880 Why? Is just replace both commands in your own example, nothing too tricky. – Fran Jul 22 '17 at 9:37
7

enter image description here

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}

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.