3

I'm trying to change the background colors and \hlines, but the result isn't what I expected.

This is the code I use:

\documentclass[a4paper,10pt,twoside,openright]{scrreprt} 
\usepackage[brazil]{babel} 
\usepackage[pdftex,luatex,usenames,dvipsnames]{color}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{graphicx} 
\usepackage{amsmath} 
\usepackage{multirow}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{array} 
\usepackage{colortbl}
\usepackage[sfdefault]{roboto}

\definecolor{azul}{RGB}{31,90,153} \definecolor{quadro}{RGB}{201,214,229}

\newcommand\mrh{\color{white}\bfseries} \newcommand\mrc[1]{\begin{tabular}{@{}l@{}} #1 \end{tabular}} \setlength\arrayrulewidth{1.0pt}

\begin{document}

\begin{table}[tbh] \centering \caption{Nova tabela avaliação nutricional em crianças menores de 5 anos} \renewcommand\arraystretch{1.5} \arrayrulecolor{white} \begin{small} \begin{tabular}{|l|c|c|c|c|} \hline \rowcolor{azul} & \mrh{Peso para idade} & \mrh{Peso para estatura} & \mrh{IMC para idade} & \mrh{Estatura para idade} \ \hline \rowcolor{quadro} \textbf{Abaixo de -3 DP} & Muito baixo peso & Magreza acentuada & Magreza acentuada & Muito baixa estatura \ \hline \rowcolor{quadro} \textbf{Entre -3 e -2 DP} & Baixo peso & Magreza & Magreza & Baixa estatura \ \hline \rowcolor{quadro} \textbf{Entre -2 e -1 DP} & \multirow{3}{}{Peso adequado} & \multirow{2}{}{Eutrofia} & \multirow{2}{}{Eutrofia} & \multirow{5}{}{Estatura adequada} \ \cline{1-1} \rowcolor{quadro} \textbf{Entre -1 e +1 DP} & & & & \ \cline{1-1} \cline{3-4} \rowcolor{quadro} \textbf{Entre +1 e +2 DP} & & Risco de sobrepeso & Risco de sobrepeso & \ \cline{1-4} \rowcolor{quadro} \textbf{Entre +2 e +3 DP} & \multirow{2}{*}{Peso elevado} & Sobrepeso & Sobrepeso & \ \cline{1-1} \cline{3-4} \rowcolor{quadro} \textbf{Acima de +3 DP} & & Obesidade & Obesidade & \ \hline \end{tabular} \end{small}% \ \centering \footnotesize{\textbf{Fonte:} adaptado do Manual de Avaliação Nutricional da Sociedade Brasileira de Pediatria (2009)} \end{table}

\end{document}

This is the result:

Wrong colored background table

Can anyone help me to fix it and it looks better?

gkruppa
  • 33

2 Answers2

5

With a simple tabular environment such colored tables are not too straigh-forward to build. In reference to existing Q&As on the issues of background colors in multirow cells and rules in colored multirow cells you could do the following:

Use negative integers for \multirow commands and place the text in the lowermost cell. This way, the background color in the cell in the next row(s) won't cover the text.

Use the hhline package to draw the partial rules, but note that you need to change the color various times in order to get the inteded result.

\documentclass{article}
\usepackage[margin=2cm]{geometry}
\usepackage{multirow, hhline, colortbl}
\usepackage[sfdefault]{roboto}

\definecolor{azul}{RGB}{31,90,153} \definecolor{quadro}{RGB}{201,214,229}

\newcommand\mrh{\color{white}\bfseries} \newcommand\mrc[1]{\begin{tabular}{@{}l@{}} #1 \end{tabular}} \setlength\arrayrulewidth{1.0pt}

\begin{document}

\begin{table} \caption{Nova tabela avaliação nutricional em crianças menores de 5 anos} \renewcommand\arraystretch{1.5} \arrayrulecolor{white} \begin{small} \begin{tabular}{|l|c|c|c|c|} \hline \rowcolor{azul} & \mrh{Peso para idade} & \mrh{Peso para estatura} & \mrh{IMC para idade} & \mrh{Estatura para idade} \ \hline \rowcolor{quadro} \textbf{Abaixo de -3 DP} & Muito baixo peso & Magreza acentuada & Magreza acentuada & Muito baixa estatura \ \hline \rowcolor{quadro} \textbf{Entre \textminus 3 e \textminus 2 DP} & Baixo peso & Magreza & Magreza & Baixa estatura \ \hline \rowcolor{quadro} \textbf{Entre \textminus 2 e \textminus 1 DP} & & & & \ \hhline{>{\arrayrulecolor{white}}->{\arrayrulecolor{quadro}}----} \rowcolor{quadro} \textbf{Entre \textminus 1 e +1 DP} & & \multirow{-2}{}{Eutrofia} & \multirow{-2}{}{Eutrofia} & \ \hhline{>{\arrayrulecolor{white}}->{\arrayrulecolor{quadro}}->{\arrayrulecolor{white}}-->{\arrayrulecolor{quadro}}-} \rowcolor{quadro} \textbf{Entre +1 e +2 DP} & \multirow{-3}{}{Peso adequado} & Risco de sobrepeso & Risco de sobrepeso & \ \hhline{>{\arrayrulecolor{white}}---->{\arrayrulecolor{quadro}}-} \rowcolor{quadro} \textbf{Entre +2 e +3 DP} & & Sobrepeso & Sobrepeso & \ \hhline{>{\arrayrulecolor{white}}->{\arrayrulecolor{quadro}}->{\arrayrulecolor{white}}-->{\arrayrulecolor{quadro}}-} \rowcolor{quadro} \textbf{Acima de +3 DP} & \multirow{-2}{}{Peso elevado} & Obesidade & Obesidade & \multirow{-5}{*}{Estatura adequada} \ \hline \end{tabular} \end{small}% \ \centering \footnotesize{\textbf{Fonte:} adaptado do Manual de Avaliação Nutricional da Sociedade Brasileira de Pediatria (2009)} \end{table}

\end{document}

enter image description here

Things are easier to achieve with the tabularray or the nicematrix packages. Look around on this site to find examples or look into the above linked manuals.

2

For information. Here is a way to create that table with {NiceTabular} of nicematrix.

\documentclass{article}
\usepackage[margin=2cm]{geometry}
\usepackage[sfdefault]{roboto}
\usepackage{nicematrix}
\usepackage{xcolor}

\begin{document}

\begin{table} \caption{Nova tabela avaliação nutricional em crianças menores de 5 anos} \renewcommand\arraystretch{1.5} \centering \small \begin{NiceTabular}{lcccc}[hvlines-except-borders,rules={color=white,width=1pt}] \CodeBefore \rowcolor[RGB]{31,90,153}{1} \rowcolor[RGB]{201,214,229}{2-*} \Body & Peso para idade & Peso para estatura & IMC para idade & Estatura para idade \ Abaixo de -3 DP & Muito baixo peso & Magreza acentuada & Magreza acentuada & Muito baixa estatura \ Entre \textminus 3 e \textminus 2 DP & Baixo peso & Magreza & Magreza & Baixa estatura \ Entre \textminus 2 e \textminus 1 DP & \Block{3-1}{Peso adequado} & \Block{2-1}{Eutrofia} & \Block{2-1}{Eutrofia} & \Block{5-1}{Estatura adequada} \ Entre \textminus 1 e +1 DP & & & & \ Entre +1 e +2 DP & & Risco de sobrepeso \ Entre +2 e +3 DP & \Block{2-1}{Peso elevado} & Sobrepeso & Sobrepeso \ Acima de +3 DP & & Obesidade & Obesidade \ \end{NiceTabular} \ \footnotesize{\textbf{Fonte:} adaptado do Manual de Avaliação Nutricional da Sociedade Brasileira de Pediatria (2009)} \end{table}

\end{document}

Output of the above code

F. Pantigny
  • 40,250