2

Consider the following MWE:

\documentclass{article}
\usepackage{colortbl}
\usepackage{tabularx}
\begin{document}
\begin{table}
\begin{tabularx}{\textwidth}{rX}
Right Right Right & Text \\ 
Right Right Right & Text \\ 
\rowcolor{red}   
\multicolumn{1}{c}{\textbf{Center}} & \\
Right Right Right  &{\small \rule{0pt}{3ex}} Small space \\
\end{tabularx}
\end{table}
\end{document}

For me this displays as enter image description here

How can I make the whole row red instead of just the second-column part of the row, i.e. "Center" should also be red?

(Note: If a solution is very complicated because of the multicolumn (without that it displayes just fine), is there then any other way to make Center be at the center of its cell?)

  • 1
    I'm not sure what the problem is here. The whole row is red. – Alan Munn Jul 26 '17 at 20:26
  • @AlanMunn Please see my edit. – l7ll7 Jul 26 '17 at 20:39
  • I see the picture, but you haven't changed the code, and for me the whole row is red. (TL 2017). Perhaps you have an outdated version of something? Add \listfiles to the document and post the output. – Alan Munn Jul 26 '17 at 20:47
2

Like this?

enter image description here

\rowcolor{...} doesn't coloring cells in \multicolumn, so in it you need to additional define cell color with \cellcolor{...}:

\documentclass{article}
\usepackage{colortbl}
\usepackage{tabularx}
\begin{document}
\begin{table}
\begin{tabularx}{\textwidth}{rX}
Right Right Right & Text \\
Right Right Right & Text \\
\rowcolor{red}
\multicolumn{1}{c}{\cellcolor{red}{\textbf{Center}}} & \\ % added cellcolor in multicolum
Right Right Right  &{\small \rule{0pt}{3ex}} Small space \\
\end{tabularx}
\end{table}
\end{document}

Edit: Here something very weird happens. Now I can't reproduce OP's problem, provided MWE works fine without added \cellcolor in \multicoumn cell. Frankly said, now I'm confused about what is going on (see comments below).

  • Were you able to reproduce the problem? – Alan Munn Jul 26 '17 at 21:11
  • I didn't check colortbl yet, but my experiences show, that celss in \multicolumn{... are hidden to \rowcolor, so you need to color this multicolumn cell again with \cellcolor. – Zarko Jul 26 '17 at 21:17
  • 1
    Weird, because it works fine without \cellcolor for me. – Alan Munn Jul 26 '17 at 21:18
  • 1
    @AlanMunn, yes, it is really weird. When I first time test OP MWE, it gives me result as (s)he show in question, but now I can't reproduce this result. all row is read without adding cellcolor. But as I mentioned in my answer, similar result has been happen to me too, and I solve the problem as I show in answer, but never deeply investigate this "phenomena". Now I'm confused ... (and temporary haven't time to investigate, whats going on. maybe tomorow evening, when my planed travel will finish). – Zarko Jul 26 '17 at 21:51

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.