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.

Please help me.
I have a problem with this table. I have other tables in my document, but rowcolor worked fine. Particularly, this code of my table has something wrong.
I want the header colored with gray.

\documentclass{article}

\usepackage{xcolor}
\usepackage{color, colortbl}
\definecolor{Gray}{gray}{0.9}
\usepackage{caption}
\usepackage{multirow,array}

\begin{document}
\begin{table}[H]
\caption{Title}
\centering
\begin{tabular}{|>{\raggedright\arraybackslash}m{50mm}|>{\raggedleft\arraybackslash}m{20mm}|>{\raggedleft\arraybackslash}m{20mm}|>{\raggedleft\arraybackslash}m{20mm}|}
\hline
\rowcolor{Gray} \multicolumn{1}{|c|}{\textbf{Text}} & \multicolumn{1}{>{\centering\arraybackslash}m{20mm}|}{\textbf{Text}} & \multicolumn{1}{>{\centering\arraybackslash}m{20mm}|}{\textbf{Text}} & \multicolumn{1}{>{\centering\arraybackslash}m{20mm}|}{\textbf{Text}}\\
    \hline
    \rowcolor{Gray} \textbf{Descripción} & \textbf{Nº} & \textbf{Sueldo mes} & \textbf{Total Año}\\\hline
\textbf{Text} & Text & & Text\\
\textbf{Text} & Text & & Text\\
\hline
\end{tabular}

\end{table}

\end{document}

image

share|improve this question
    
@HarishKumar Thanks, but i defined the color in the preamble. I've just change the code. –  Isai Jan 19 '13 at 1:42
    
Your code works for me. May be you need an update of your tex distro.? –  Harish Kumar Jan 19 '13 at 1:44
    
@HarishKumar I have a question, if I define a new row without multicolumn, it works: \hline \hline \rowcolor{Gray} \textbf{Text} & \textbf{Text} & \textbf{Text} & \textbf{Text}\\\hline \hline May have something more in the code of the row where there are multicolumn commands? –  Isai Jan 19 '13 at 2:00
    
It works as it is for me! More details may be needed here. –  Harish Kumar Jan 19 '13 at 2:04
    
@HarishKumar I answered the question, with rowcolor in each cell. Thanks. –  Isai Jan 19 '13 at 2:33

1 Answer 1

up vote 0 down vote accepted

For people who has the same problem, this code works for me; I defined the \multicolumn{1}{|c|}{\rowcolor{Gray}\textbf{Text}} for each cell, instead of define de \rowcolor at the beginning of the row.

\documentclass{article}

\usepackage{color, colortbl}
\definecolor{Gray}{gray}{0.9}
\usepackage{caption}

\begin{document}
\begin{table}[H]
\caption{Title}
\centering
\begin{tabular}{|>{\raggedright\arraybackslash}m{50mm}|>{\raggedleft\arraybackslash}m{20mm}|>{\raggedleft\arraybackslash}m{20mm}|>{\raggedleft\arraybackslash}m{20mm}|}
\hline
\multicolumn{1}{|c|}{\rowcolor{Gray}\textbf{Text}} & \multicolumn{1}{>{\centering\arraybackslash}m{20mm}|}{\rowcolor{Gray}\textbf{Text}} & \multicolumn{1}{>{\centering\arraybackslash}m{20mm}|}{\rowcolor{Gray}\textbf{Text}} & \multicolumn{1}{>{\centering\arraybackslash}m{20mm}|}{\rowcolor{Gray}\textbf{Text}}\\
\hline
\textbf{Text} & Text & & Text\\
\textbf{Text} & Text & & Text\\
\hline
\end{tabular}

\end{table}


\end{document}
share|improve this answer
1  
Of course you mean \cellcolor, because \rowcolor there will raise an error. But the table in your question compiles perfectly for me. –  egreg Jan 19 '13 at 9:50
    
@egreg Maybe, the software I use miss some update, as HarishKumar said. I work in Texpad software. Anyway, cellcolor also works for me. –  Isai Jan 20 '13 at 18:13

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.