1

I am trying to produce a colored table but the separation lines and the border lines are creating blank spaces that ruins the aesthetics of the table. I wish to remove them.

enter image description here

Here is the code I'm using

\usepackage{multirow}
\usepackage{booktabs}
\usepackage{hhline}
\usepackage[table]{xcolor}

\begin{document}

\begin{table}[h]
\centering
\begin{tabular}{l*8cl}
\toprule
\rowcolor[HTML]{A4CAF6} 
\multicolumn{1}{c}{\cellcolor[HTML]{A4CAF6}}                            & \multicolumn{8}{c}{\cellcolor[HTML]{A4CAF6}Temperatura $[^{\circ}C]$} & \cellcolor[HTML]{A4CAF6}                             \\ \cmidrule(lr){2-9}
\rowcolor[HTML]{A4CAF6} 
\multicolumn{1}{c}{\multirow{-2}{*}{\cellcolor[HTML]{A4CAF6}Propiedad}} & 25     & 50     & 100     & 150    & 200    & 250    & 300    & 350    & \multirow{-2}{*}{\cellcolor[HTML]{A4CAF6}Referencia} \\
\rowcolor[HTML]{FFFFC7} 
$Rp_{0,2} [MPa]$                                                          &        &        &         &        &        &        &        &        &                                                      \\ 
\rowcolor[HTML]{CFCFCF} 
$UTS [MPa]$                                                               &        &        &         &        &        &        &        &        &                                                      \\ \bottomrule
\end{tabular}
\end{table}

\end{document}
leandriis
  • 62,593
Patricio
  • 11
  • 1

2 Answers2

1

With the lastest version of nicematrix (4.0 of 2020/05/08), you can have the result easily (you need several compilations).

\documentclass{article}
\usepackage{multirow}
\usepackage{booktabs}
\usepackage{siunitx}

\usepackage{nicematrix}

\definecolor{myblue}{HTML}{A4CAF6}
\definecolor{myyellow}{HTML}{FFFFC7}
\definecolor{mygray}{HTML}{CFCFCF}

\begin{document}

\begin{table}[h]
\centering
\begin{NiceTabular}{L*{8}{C}L}[code-before = \rowcolor{myblue}{1,2} \rowcolor{myyellow}{3} \rowcolor{mygray}{4}]
\toprule
\multirow{2}{*}{Propiedad} & \multicolumn{8}{C}{Temperatura [\si{\celsius}]} & \multirow{2}{*}{Referencia}\\
\cmidrule{2-9}
 & 25 & 50 & 100 & 150 & 200 & 250 & 300 & 350 \\
R\textsubscript{p0,2} [\si{\mega\pascal}] \\
UTS [\si{\mega\pascal}] \\
\bottomrule
\end{NiceTabular}
\end{table}

\end{document}

Result of the above code

F. Pantigny
  • 40,250
  • Nice new features of nicematrix. A question: is possible to add more vertical space to table cells ( I steal read new documentation)? +1! – Zarko May 13 '20 at 11:27
  • I assume you bother about the yellow gray rows. It's possible to use \extrarowheight and \arraystretch as usual. However, in this case, these parameters would also affect the blue zone which is perfect. It's possible to use \\[...] as usual but such a tuning beetween the yellow row and the gray one would increase the depth of the yellow row and not the height of the gray one. Eventually, I don't see other mean than adding manual struts in the yellow and gray rows... – F. Pantigny May 13 '20 at 12:02
  • Francly said, I hope that there is way to use for example cellspace. I will make some more test late evening. – Zarko May 13 '20 at 12:09
  • In this answer, since version 5.0 of nicematrix one must write l*{8}{c}l instead of L*{8}{C}L in the preamble of {NiceTabular} (but there is an option for backward compatibility). – F. Pantigny Jul 18 '20 at 20:56
0

Here is my suggestion. In order to get rid of the white line, you can use \hhline{>{\arrayrulecolor[HTML]{A4CAF6}}->{\arrayrulecolor{black}}-------->{\arrayrulecolor[HTML]{A4CAF6}}->{\arrayrulecolor{black}}}. This will fill the white gap with a line in the same color as the background.

Instead of repeating the HTML color definition over and over, I suggest defining the color in the preamble and using this predefined color throughout your document. This will make thing much easier if you later on decide to change the color. You will then only have to chenge the definition in the preamble instead of changing the color of every single cell. In the following MWE I have used such a globally defined color.

I have also added the siunitx package for the units °C and MPa. I have also changed the code for Rp0,2 and UTS (assuming that these correpsond to yield strength and ultimate tensile strength) since using math mode for abbreviations is not recommended. If you want UTS to show up in italic, use \textit{UTS} instead.

For the second table, I have added the cellspace packagein order to add some vertical space above and below the text in each cell to avoid overlap with the horizontal lines.

enter image description here

\documentclass{article}
\usepackage{multirow}
\usepackage{booktabs}
\usepackage{hhline}
\usepackage[table]{xcolor}
\usepackage{siunitx}

\definecolor{myblue}{HTML}{A4CAF6}
\definecolor{myyellow}{HTML}{FFFFC7}
\definecolor{mygray}{HTML}{CFCFCF}

\usepackage[column=0]{cellspace}
\setlength\cellspacetoplimit{0.5\tabcolsep}
\setlength\cellspacebottomlimit{\cellspacetoplimit}
\begin{document}

\begin{table}[h]
\centering
\begin{tabular}{l*8cl}
\hline
\rowcolor[HTML]{A4CAF6} 
\multicolumn{1}{c}{\cellcolor{myblue}}                            & \multicolumn{8}{c}{\cellcolor{myblue}Temperatura [\si{\celsius}]} & \cellcolor{myblue}                             \\ 
\hhline{>{\arrayrulecolor{myblue}}->{\arrayrulecolor{black}}-------->{\arrayrulecolor{myblue}}->{\arrayrulecolor{black}}}
\rowcolor{myblue} 
\multicolumn{1}{c}{\multirow{-2}{*}{\cellcolor{myblue}Propiedad}} & 25     & 50     & 100     & 150    & 200    & 250    & 300    & 350    & \multirow{-2}{*}{\cellcolor{myblue}Referencia} \\
\rowcolor{myyellow} 
R\textsubscript{p0,2} [\si{\mega\pascal}]                                                          &        &        &         &        &        &        &        &        &                                                      \\ 
\rowcolor{mygray} 
UTS [\si{\mega\pascal}]                                                               &        &        &         &        &        &        &        &        &                                                      \\ \hline
\end{tabular}
\end{table}


\begin{table}[h]
\centering
\begin{tabular}{0l*{8}{0c}0l}
\hline
\rowcolor[HTML]{A4CAF6} 
\multicolumn{1}{c}{\cellcolor{myblue}}                            & \multicolumn{8}{c}{\cellcolor{myblue}Temperatura [\si{\celsius}]} & \cellcolor{myblue}                             \\ 
\hhline{>{\arrayrulecolor{myblue}}->{\arrayrulecolor{black}}-------->{\arrayrulecolor{myblue}}->{\arrayrulecolor{black}}}
\rowcolor{myblue} 
\multicolumn{1}{c}{\multirow{-2}{*}{\cellcolor{myblue}Propiedad}} & 25     & 50     & 100     & 150    & 200    & 250    & 300    & 350    & \multirow{-2}{*}{\cellcolor{myblue}Referencia} \\
\rowcolor{myyellow} 
R\textsubscript{p0,2} [\si{\mega\pascal}]                                                          &        &        &         &        &        &        &        &        &                                                      \\ 
\rowcolor{mygray} 
UTS [\si{\mega\pascal}]                                                               &        &        &         &        &        &        &        &        &                                                      \\ \hline
\end{tabular}
\end{table}

\end{document}
leandriis
  • 62,593