如何扩展表格行颜色以填充表格宽度

如何扩展表格行颜色以填充表格宽度

我有一张表格。我想给一些行着色。问题是颜色不能填满整行。表格如下所示:

在此处输入图片描述

如何扩展行颜色以便填满整行?

剧本:

\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}

答案1

使用\begin{tabularx}{\columnwidth}{llX}, 而不是{lll}来定义列类型。

\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}

在此处输入图片描述

相关内容