1

I am trying to make a table with colored cells and white grid lines, in it there are some cells that cover several rows. The problem is that when I use \multirow and \cellcolor to achieve this, the horizontal line in the \multirow cel is still appearing. This is what I am getting: enter image description here

And here is my code:

\documentclass{article}
\usepackage[a4paper,margin=1in]{geometry}
\usepackage[svgnames]{xcolor}
\usepackage{tabularx,multirow,hhline,colortbl}
\usepackage{hhline}

\definecolor{headers}{RGB}{0,137,182}
\definecolor{M1}{RGB}{163,195,217}
\definecolor{M2}{RGB}{155,214,220}


\begin{document}
    \setlength\arrayrulewidth{1pt}
    \newcolumntype{L}{>{\raggedright\arraybackslash}X}
    \begin{tabularx}{\textwidth}{>{\raggedright\arraybackslash}m{0.25\textwidth} !{\color{white}\vrule width 1pt} L !{\color{white}\vrule width 1pt} >{\raggedright\arraybackslash}p{0.25\textwidth}l}
        \rowcolor{headers}
        \centering\textbf{\textcolor{white}{Ministries}} & \centering\textbf{\textcolor{white}{National Agencies}} & \textbf{\textcolor{white}{Regional Agencies}}\\
        \arrayrulecolor{white}\hline
        \rowcolor{M1}
        Ministry of the Interior&&Regional Council of Souss-Massa\\
        \arrayrulecolor{white}\hline
        \cellcolor{M2}&\cellcolor{M2}National Office for Electricity and Drinking Water (ONEE)&\cellcolor{M2}\\
        \hhline{~--}
        \cellcolor{M2}&\cellcolor{M2}&\cellcolor{M2}&\\
        \hhline{~--}
        \cellcolor{M2}&\cellcolor{M2}&\cellcolor{M2}&\\
        \hhline{~--}
        \cellcolor{M2}&\cellcolor{M2}&\cellcolor{M2}&\\
        \hhline{~--}
        \cellcolor{M2}&\cellcolor{M2}&\cellcolor{M2}&\\
        \hhline{~--}
        \multirow{-6}{0.25\textwidth}{\cellcolor{M2}Ministry of Energy, Mines, and Sustainable Development}&\cellcolor{M2}&\cellcolor{M2}&\\
    \end{tabularx}
\end{document}

Thank you for any guidance!

2 Answers 2

3

lie this?

enter image description here

what you see as rules in your table are actually gaps between cells with size of rules thicknes. they appear as rules since you have all rules in white color ...

this gaps can be colored with part of rule in multirow cell:

\documentclass{article}
\usepackage[a4paper,margin=1in]{geometry}
\usepackage[svgnames,table]{xcolor}
\usepackage{makecell, multirow, tabularx}
    \newcolumntype{L}{>{\raggedright\arraybackslash}X}
    \renewcommand\theadfont{\normalsize\bfseries\color{white}}
\usepackage{hhline}

\definecolor{headers}{RGB}{0,137,182}
\definecolor{M1}{RGB}{163,195,217}
\definecolor{M2}{RGB}{155,214,220}


\begin{document}
    \setlength\arrayrulewidth{2pt}
    \arrayrulecolor{white}
    \def\clinecolor{\hhline{|>{\arrayrulecolor{M2}}-%
             >{\arrayrulecolor{white}}|-|-|}}
    \begin{tabularx}{\textwidth}%
    {|
    >{\hsize=0.5\hsize\columncolor{M2}}L
     |
    >{\columncolor{M2}}L
     |
    >{\hsize=0.5\hsize\columncolor{M2}}L
     |
    }
    \rowcolor{headers}
\thead{Ministries}          & \thead{National Agencies} & \thead{Regional Agencies}         \\
    \hhline{|-|-|-|}
    \rowcolor{M1}
Ministry of the Interior    &                           & Regional Council of Souss-Massa   \\
    \hhline{|-|-|-|}
                            & National Office for Electricity and Drinking Water (ONEE)
                                                        &                                   \\
    \clinecolor
                            &                           &                                   \\
    \clinecolor
                            &                           &                                   \\
    \clinecolor
                            &                           &                                   \\
    \clinecolor                                &                           &                                   \\
    \clinecolor
\multirow{-7}{=}{Ministry of Energy, Mines, and Sustainable Development}
                            &                           &                                   \\
    \end{tabularx}
\end{document}

in above mwe i use thead from makecel for column headers and also change the way how to color table. with this the table code is shorter and more clear. I also removed not used last column l.

Addendum: After almost four year ... Now is available new table type tabularray, which is based on LaTeX3. It introduce new paradigm of table settings. In your case using it the packages hhline, makecell, multirow and tabularx are not needed anymore, the code is simpler and more concise (and consequently shorter).

\documentclass{article}
\usepackage[a4paper,margin=1in]{geometry}
\usepackage[table]{xcolor}
\usepackage{tabularray}

\definecolor{headers}{RGB}{0,137,182}
\definecolor{M1}{RGB}{163,195,217}
\definecolor{M2}{RGB}{155,214,220}

\begin{document}
    \begin{tblr}{
colspec ={X[1.3] X[2] X[1]},
hlines = {white,1pt},
vlines = {white,1pt},
row{1}  = {headers, font=\bfseries, fg=white},
row{2}  = {M1},
row{3-9}  = {M2},
cell{3}{1} = {r=7,c=1}{l,M2},
%
colsep=3pt, rowsep=3pt
                }
Ministries                  &   National Agencies   &   Regional Agencies   \\
Ministry of the Interior    &                       & Regional Council of Souss-Massa       \\
Ministry of Energy, Mines, and Sustainable Development
                            &    National Office for Electricity and Drinking Water (ONEE)  \\
                            &                       &                                       \\
                            &                       &                                       \\
                            &                       &                                       \\
                            &                       &                                       \\
                            &                       &                                       \\
                            &                       &                                       \\
    \end{tblr}
\end{document}

In comparison to the first solution, the result is much better as before (no problems with hlines:

enter image description here

2
  • Thank you for the answer, this is the correct answer to my question, however I find a bit annoying the vector lines that this method leaves in the background, thus I ended up using a tikz matrix to do the job. Thank you so much though, it was very helpful! Nov 29, 2017 at 19:09
  • @CamiloRamirez, frankly said, i wouldn't use colored table ... (see wiert.me/2014/04/03/… why). and yes, what you like to achieve is far more easy to do in tikz. happy tex-ing!
    – Zarko
    Nov 29, 2017 at 19:15
1

With {NiceTabular} of nicematrix.

In {NiceTabular}, you merge cells both horizontally and vertically with the command \Block. For the rows, you give the number of logical rows (and not the number of physical lines as with \multicolumn).

With the key hvlines, all the rules are drawn, excepted in the blocks (constructed by \Block). With hvlines-except-borders, the borders are not drawn (there is no point drawing an exterior white border here).

\documentclass{article}
\usepackage[a4paper,margin=1in]{geometry}
\usepackage{nicematrix}

\begin{document}

\begin{center}

\setlength{\arrayrulewidth}{2pt}

\begin{NiceTabular}[hvlines-except-borders,rules/color=white]
     {p[l]{0.25\textwidth}X[l]p[l]{0.25\textwidth}}
\CodeBefore
  \rowcolor[RGB]{0,137,182}{1}
  \rowcolor[RGB]{163,195,217}{2}
  \rowcolor[RGB]{155,214,220}{3-}
\Body
  \RowStyle[color=white]{\centering\bfseries\sffamily} 
  Ministries               & National Agencies & Regional Agencies \\
  Ministry of the Interior &                   & Regional Council of Souss-Massa \\
  \Block{*-1}{Ministry of Energy Mines, and Sustainable Development} 
                           & National Office for Electricity and Drinking Water (ONEE) \\
  \\
  \\
  \\
  \\
  \\
  \\
\end{NiceTabular}

\end{center}

\end{document}

You need several compilations (because nicematrix uses PGF/Tikz nodes under the hood).

Output of the above code

1
  • For such types of tables your package is superior solution (first +1 is mine ;-) )
    – Zarko
    Jul 26, 2021 at 12:46

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .