1

I have created a table with tabular and cellcolor, and you know what hapends: the cell color overlap the border.

I have found that this is often solved with hhline. In order to change the color in lines over colored cells I've read that it's useful to use arrayrulecolor. In other words, to avoid this:

Table using \hhline{~~-----}

The previous table is defined by the following LaTex code:

\begin{table}[h]
    \centering
    \setlength\arrayrulewidth{0.8pt}
    \begin{tabular}{|c|c|c|c|c|c|c|}
        \hhline{-------}
        
        \rowcolor[HTML]{EFEFEF} \cellcolor[HTML]{EFEFEF} & \cellcolor[HTML]{EFEFEF} & \cellcolor[HTML]{EFEFEF} &
        \multicolumn{4}{c|}{\cellcolor[HTML]{EFEFEF}\textbf{Acción}} \\ 
        
        \hhline{~~~----}
        
        \rowcolor[HTML]{EFEFEF} \multirow{-2}{*}{\cellcolor[HTML]{EFEFEF}\textbf{$n_{d}$}} &
        \multirow{-2}{*}{\cellcolor[HTML]{EFEFEF}\textbf{$n_{o}$}} &
        \multirow{-2}{*}{\cellcolor[HTML]{EFEFEF}\textbf{Estado}} &
        \textbf{Avance} &\textbf{Retroceso} &
        \textbf{\begin{tabular}[c]{@{}c@{}}Giro\\ Antihorario\end{tabular}} &
        \textbf{\begin{tabular}[c]{@{}c@{}}Giro\\ Horario\end{tabular}} \\  
            
        \hhline{-------}
        
        \cellcolor[HTML]{FFF1F1} 0 & \cellcolor[HTML]{FFF1F1}\textbf{0} & \cellcolor[HTML]{FFF1F1}\textbf{0} &
        \textit{0} & \textit{0} & \textit{0} & \textit{0} \\ 
        
        \hhline{~------}
    
        \cellcolor[HTML]{FFF1F1} & \cellcolor[HTML]{FFF1F1}\textbf{1} & \cellcolor[HTML]{FFF1F1}\textbf{1} &
        \textit{0} & \textit{0} & \textit{0} & \textit{0} \\ 
        
        \hhline{-------} 
    \end{tabular}
\end{table}  

I've try to avoid the white lines (without success) using this:

\definecolor{tgray}{HTML}{EFEFEF}
\definecolor{tblack}{HTML}{000000}

[...]

\hhline{>{\arrayrulecolor{tgray}}->{\arrayrulecolor{tgray}}->{\arrayrulecolor{tgray}}->{\arrayrulecolor{tblack}}----}

The result is a whole black line:

Table using \arrayrulecolor with \hhline

As you can see, my problem is not solve with arrayrulecolor. Do you know how to make this successfully?

Even so, if you know another way to make tables which don't depends on the pdf viewer (with the solution I exposed here, with some levels of ZOOM some lines still don't apperar), it would be too profitable to me.

Thanks.

2

You can easily do that with {NiceTabular} of nicematrix.

\documentclass{article}
\usepackage[svgnames]{xcolor}
\usepackage{nicematrix}
\usepackage{makecell}

\begin{document}
\begin{NiceTabular}{ccccccc}%
  [ 
    hvlines ,
    code-before = \rowcolor{Gainsboro!50}{1,2}
                  \rectanglecolor{MistyRose!50}{3-1}{4-3}
  ]
\hphantom{$n_d$}\Block{2-1}{$n_d$}&\Block{2-1}{$n_0$}&\hphantom{Estado}\Block{2-1}{Estado} & \Block{1-4}{Acción} \\
&&& Avance & Retroceso & \makecell{Giro\\ Antihorario} & \makecell{Giro\\Horario} \\
\Block{2-1}{0}
& 0 & 0 & 0 & 0 & 0 & 0 \\
& 1 & 1 & 0 & 0 & 0 & 0 \\
\end{NiceTabular}
\end{document} 
  • In {NiceTabular}, you can merge cells with \Block, both horizontally and vertically (however, the blocks don't create space by themselves).

  • With the key hvlines, you draw all the rules excepted in the blocks.

  • You have tools to color, rows columns and cells. With these tools, you won't have artefacts in some PDF viewers as you have sometimes with the tools of colortbl.

Ouput of the current buffer

| improve this answer | |
  • 1
    wow This solve all my problems with tables, thanks so much! – Francisco J Naranjo Aug 4 at 10:42
1

Here's how to do it with hhline. I replaced, for the coloured part of the lines, your colours with named colours from svgnames (nearly the same as yours) to have a shorter code.

\documentclass{article}
\usepackage{array, multirow}
\usepackage[table, svgnames]{xcolor}
\usepackage{hhline}
\newcommand*{\arb}{\arrayrulecolor{black}}
\newcommand*{\argr}{\arrayrulecolor{Gainsboro!50}}

\begin{document}

\begin{table}[h]
    \centering
    \setlength\arrayrulewidth{0.8pt}
    \begin{tabular}{|c|c|c|c|c|c|c|}
        \hhline{-------}

        \rowcolor{Gainsboro!50} & & &
        \multicolumn{4}{c|}{\textbf{Acción}} \\%[HTML]{EFEFEF}r[HTML]{EFEFEF} \cellcolor[HTML]{EFEFEF}

        \hhline{|>{\argr}->{\arb}|>{\argr}->{\arb}|>{\argr}->{\arb}|----|}

        \rowcolor{Gainsboro!50} \multirow{-2}{*}{\textbf{$n_{d}$}} &
        \multirow{-2}{*}{\textbf{$n_{o}$}} &
        \multirow{-2}{*}{\textbf{Estado}} &
        \textbf{Avance} &\textbf{Retroceso} &
        \textbf{\begin{tabular}[c]{@{}c@{}}Giro\\ Antihorario\end{tabular}} &
        \textbf{\begin{tabular}[c]{@{}c@{}}Giro\\ Horario\end{tabular}} \\

        \hhline{-------}

        \cellcolor[HTML]{FFF1F1} 0 & \cellcolor[HTML]{FFF1F1}\textbf{0} & \cellcolor[HTML]{FFF1F1}\textbf{0} &
        \textit{0} & \textit{0} & \textit{0} & \textit{0} \\

        \hhline{|>{\arrayrulecolor{MistyRose!50}}->{\arb}|------}

        \cellcolor[HTML]{FFF1F1} & \cellcolor[HTML]{FFF1F1}\textbf{1} & \cellcolor[HTML]{FFF1F1}\textbf{1} &
        \textit{0} & \textit{0} & \textit{0} & \textit{0} \\

        \hhline{-------}
    \end{tabular}
\end{table}

\end{document} 

enter image description here

| improve this answer | |

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.