1

I have a table. I want to color some rows. The problem is that the color does not fill the whole row. The table looks like this:

enter image description here

How to expand the row color so that it fills the whole row?

the script:

\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

\hyphenation{op-tical net-works semi-conduc-tor}
\usepackage{underscore} %for underscores
\usepackage[font=itshape]{quoting} %for double quotation
\usepackage{graphicx} %for images
\usepackage{ifpdf}

\usepackage{colortbl}%table rows color

\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{threeparttable, tablefootnote}

\usepackage{lipsum}

\begin{document}
\lipsum
\begin{table}[tp]
\centering
\begin{tabularx}{\columnwidth}{lll}
\toprule
A & B & C \\
\midrule
\rowcolor[gray]{.9}
01 & AAA~1.0        & Aaaaaaaaaaa aaaaaaaa aaa \\ 
02 & BBB~2.0        & Bbbbbbbbbbb bbbbbbbb bbb \\  
\bottomrule
\\
\end{tabularx}
\caption{Table 1}
\label{table:table1}
\end{table}
\end{document}
  • never use tabularx without an X column, althoigh I would not use tabularx here, I would just use tabular – David Carlisle Aug 14 '17 at 12:16
0

Use \begin{tabularx}{\columnwidth}{llX}, instead of {lll} to define the column types.

\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

\hyphenation{op-tical net-works semi-conduc-tor}
\usepackage{underscore} %for underscores
\usepackage[font=itshape]{quoting} %for double quotation
\usepackage{graphicx} %for images
\usepackage{ifpdf}

\usepackage{colortbl}%table rows color

\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{threeparttable, tablefootnote}

\usepackage{lipsum}

\begin{document}
\lipsum
\begin{table}[tp]
\centering
\begin{tabularx}{\columnwidth}{llX}
\toprule
A & B & C \\
\midrule
\rowcolor[gray]{.9}
01 & AAA~1.0        & Aaaaaaaaaaa aaaaaaaa aaa \\ 
02 & BBB~2.0        & Bbbbbbbbbbb bbbbbbbb bbb \\  
\bottomrule
\\
\end{tabularx}
\caption{Table 1}
\label{table:table1}
\end{table}
\end{document}

enter image description here

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.