Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I would like to have the first row of all my tables colored with a certain color (below yellow) but somehow below thing is not working as expected

This:

\documentclass[a4paper, 12pt]{report}
\usepackage{colortbl}

\begin{document}

\begin{tabular*}{0.90\textwidth}{@{\extracolsep{\fill}}ll}
\rowcolor{yellow}
OS & Features \\ \hline
iOS & blah blah.\\
Android & blah blah.\\
\end{tabular*}

\end{document}

Results in this:

enter image description here

Which is undesired because of the blank space between OS and Features Additionally I would like to make the hline a bit wider so it matches the width of the yellow area, or make the yellow area a bit narrower so it matches the horizontal line. How can i do this?

Any help is high appreciated.

share|improve this question
1  
You could do \begin{tabularx}{0.90\textwidth}{lXl} with an empty second column. –  Qrrbrbirlbel Jan 7 '13 at 4:35
    
with an empty second column : I would rather not use tricky things as much as possible since this kind of table will be used in several places :) –  nacho4d Jan 7 '13 at 4:48
    
Since you have some responses below that seem to answer your question, please consider marking one of them as ‘Accepted’ by clicking on the tickmark below their vote count (see How do you accept an answer?). This shows which answer helped you most, and it assigns reputation points to the author of the answer (and to you!). It's part of this site's idea to identify good questions and answers through upvotes and acceptance of answers. –  Qrrbrbirlbel Sep 3 '13 at 17:54

2 Answers 2

use package tabularx instead, it is a better choice than the star version of tabular

\documentclass[12pt]{report}
\usepackage{tabularx,colortbl}

\begin{document}

\begin{tabularx}{0.90\textwidth}{Xl}
\rowcolor{yellow}
OS      & Features \\ \hline
iOS     & blah blah.\\
Android & blah blah.\\
\end{tabularx}

\end{document}

enter image description here

share|improve this answer

I do not know how to patch \rowcolor (and its children), but I provide a new \Rowcolor[<pad>]{<color>} macro:

  • <color> stands for the color used, and
  • <pad> for the padding before the first column (usual \tabcolsep, which is the default) This is the width of the stuff that is @{dded} before the first row.

A note on the latter sentence: You specified @{\extracolsep{\fill}}ll which removed the \tabcolsep before the first column. The original \rowcolor can’t handle that as well, see your picture, which is the reason you asked for making the rule longer when you have in fact said, that it should be shorter! (More on that: colortbl: \rowcolor in tables with \begin{tabular}{@{}ccc@{}})

If you use something like @{}<…>, you need to use \Rowcolor[]{<color>} (which is the same as \Rowcolor[0pt]{<color>}).

Code

\documentclass[a4paper, 12pt]{report}
\usepackage{colortbl}
\usepackage{etoolbox}
\makeatletter
\newlength{\qrr@dimen@}
\expandafter\pretocmd\csname tabular*\endcsname{\setlength{\qrr@dimen@}{#1}}{}{}
\newcommand*{\Rowcolor}[2][\tabcolsep]{%
    \ifx\relax#1\relax\else
        \kern-\the\dimexpr#1\relax
    \fi
    \makebox[0pt][l]{%
        \fboxsep=0pt
        \colorbox{#2}{%
            \strut\kern\qrr@dimen@
        }%
    }%
    \ifx\relax#1\relax\else
        \kern\the\dimexpr#1\relax
    \fi
    \ignorespaces
}
\makeatother
\begin{document}
\noindent
\begin{tabular*}{.9\linewidth}{l@{\extracolsep{\fill}}l}
    \rowcolor{yellow} \multicolumn{1}{>{\columncolor{green}[\tabcolsep][\tabskip]}l}{OS} &  Features   \\ \hline
    \Rowcolor{yellow} OS &  Features   \\ \hline
    iOS                  &  blah blah. \\
    Android              &  blah blah. \\
\end{tabular*}
\end{document}

Output

enter image description here

share|improve this answer
    
who's setting \dimen@ there? (seems to work but???) –  David Carlisle Jan 7 '13 at 10:01
    
@DavidCarlisle \tabular* does: \setlength\dimen@{#1} –  Qrrbrbirlbel Jan 7 '13 at 14:14
    
so it does, sneaky (and of course bad style to assume a scratch register is safe not that there is any alternative here:-). I had a horrible feeling it might have been me that added that setting but it was Rainer so I might be forgiven for forgetting:-) 1998-05-13 Rainer Schoepf <latex-bugs@latex-project.org> * lttab.dtx Use \setlength to set size of p-column and for argument of tabular* environment, so that the benefits of the calc package apply. Note this won't work if the first column is a p column as \dimen@ will then be the column width as noted in Rainer's change log –  David Carlisle Jan 7 '13 at 14:33
    
@DavidCarlisle Well, there is one alternative: I have updated my answer with an extra dimension. Anyway, I have never used used tabular* before; I think that the tabularx environment is superior too. –  Qrrbrbirlbel Jan 8 '13 at 22:17

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.