1

I have a simple table like:

\documentclass[varwidth]{standalone}
\usepackage[table]{xcolor}
\usepackage[english]{babel}
\usepackage{multirow}

\begin{document}
    \begin{center}
        \renewcommand{\arraystretch}{1.9}
        \begin{tabular}{cc}
            \cellcolor[rgb]{0.0,0.5,1.0}Unsolvability & \multirow{2}{*}{ \cellcolor[rgb]{0.91,0.91,0.91}Chapter 7}\\
            \cellcolor[rgb]{0.0,0.5,1.0}Relaxation & \cellcolor[rgb]{0.91,0.91,0.91}\\
        \end{tabular}
    \end{center}
\end{document}

But the output is not what I exactly wants since the background color covers the cell's text.

enter image description here

How should I fix this?

egreg
  • 1,121,712

3 Answers3

3

Just change \multirow{2}{*}{...} to \multirow{-2}{*}{...}:

\documentclass[varwidth]{standalone}
\usepackage[table]{xcolor}
\usepackage[english]{babel}
\usepackage{multirow}

\begin{document}
    \begin{center}
        \renewcommand{\arraystretch}{1.9}
        \begin{tabular}{cc}
            \cellcolor[rgb]{0.0,0.5,1.0}Unsolvability & \cellcolor[rgb]{0.91,0.91,0.91}\\
            \cellcolor[rgb]{0.0,0.5,1.0}Relaxation & \multirow{-2}{*}{ \cellcolor[rgb]{0.91,0.91,0.91}Chapter 7}\\
        \end{tabular}
    \end{center}
\end{document}

enter image description here

However, in this case it's simpler to nest a tabular in the left column.

\documentclass{standalone}
\usepackage[table]{xcolor}

\renewcommand{\arraystretch}{1.9}

\definecolor{left}{rgb}{0.0,0.5,1.0}
\definecolor{right}{rgb}{0.91,0.91,0.91}

\begin{document}

\begin{tabular}{cc}
\cellcolor{left}%
  \begin{tabular}{@{}c@{}}
  Unsolvability \\ Relaxation
  \end{tabular}
& \cellcolor{right}Chapter 7
\end{tabular}

\end{document}

enter image description here

egreg
  • 1,121,712
0

with use of \columncolor is simpler:

\documentclass[varwidth]{standalone}
\usepackage[table]{xcolor}
\usepackage[english]{babel}
\usepackage{multirow}

\begin{document}
    \begin{center}
        \renewcommand{\arraystretch}{1.9}
        \begin{tabular}{>{\columncolor[rgb]{0.0,0.5,1.0}}c
                        >{\columncolor[rgb]{0.91,0.91,0.91}}c}
        Unsolvability   &                               \\
        Relaxation      & \multirow{-2}{*}{Chapter 7}   \\
        \end{tabular}
    \end{center}
\end{document}

enter image description here

Zarko
  • 296,517
  • 1
    @Roboticist, i'm lucky ones :-) – Zarko Apr 08 '18 at 19:38
  • 1
    I'm not sure, but I think that white line between "Unsolavbility" and "Relaxation" should not be there since the expression is "Unsolavbility Relaxation" as OP's screenshot implies. –  Apr 08 '18 at 19:40
  • interestingly. so far i was convinced that this is caused by pdf viewer. i don't see any reasons why the result of \columncolors be different from result if you put \cellcolor in each cell of column. question for author of colortbl package :-) – Zarko Apr 08 '18 at 19:53
0

My feeling is that you're doing a drawing task in the form of a table rather than a real table with colored cells. In this case, why not use TikZ directly? It is very powerful and relatively easy, with great documentation.

\documentclass[varwidth]{standalone}
\usepackage[table]{xcolor}
\usepackage[english]{babel}
\usepackage{multirow,tikz}

\begin{document}

\begin{center}
\begin{tikzpicture}[blk/.style={minimum height=4em,align=center}]
  \path [fill=blue!50] (0,0) rectangle (3,2) node[blk,pos=.5] {Unsolvability\\[.5em]Relaxation};
  \path [fill=gray!20] (3,0) rectangle (6,2) node[blk,pos=.5] {Chapter 7};
\end{tikzpicture}
\end{center}

\end{document}

enter image description here

AboAmmar
  • 46,352
  • 4
  • 58
  • 127