2

I have created a colored table, and I have a problem with \hhline. As you can see in the picture below, the hhline overwrites the left border of the table. How can I fix that?

(using cline is not an option, because it does not work well with colored tables).

enter image description here

Here is the code:

\begin{table}[H]
\centering
\renewcommand{\arraystretch}{1.5}
\rowcolors{2}{MidnightBlue!10}{white}
\begingroup\setlength{\fboxsep}{0pt}
 \colorbox{MidnightBlue!30}{%
\begin{tabular}{|c|c|c|c|c|} 
\hline
\rowcolor{MidnightBlue!30} & \multicolumn{2}{c|}{\textbf{test1}} & \multicolumn{2}{c|}{\textbf{test2}} \\ 
 \hhline{~|-|-|-|-|}
\rowcolor{MidnightBlue!30} & & & & \\
\rowcolor{MidnightBlue!30} \multirow{-3}{*}{test3} & \multirow{-2}{*}{\shortstack{test1\\test}} & \multirow{-2}{*}{\shortstack{test2\\test}}  & \multirow{-2}{*}{\shortstack{test1\\test}} & \multirow{-2}{*}{\shortstack{test2\\test}} \\
\hline 
test & test & test & test & test \\
test & test & test & test & test \\
\hline
\end{tabular}%
}\endgroup
\caption{\textbf{test}}
\end{table}
2
  • 2
    Probably writing \hhline{|~|-|-|-|-|} solves it.
    – Bernard
    Commented Jun 18, 2021 at 15:53
  • 3
    it 's not that hhline erased anything, you did not specify a border at that point Commented Jun 18, 2021 at 16:00

1 Answer 1

1

For information, here is a way to construct that tabular with {NiceTabular} of nicematrix. You won't have rules which seem to vanish in some PDF viewers at some levels of zoom.

\documentclass{article}
\usepackage[dvipsnames]{xcolor}
\usepackage{float}
\usepackage{nicematrix}

\begin{document}

\begin{table}[H]
\centering
\renewcommand{\arraystretch}{1.5}
\begin{NiceTabular}{ccccc}[vlines]
\CodeBefore
    \rowcolor{MidnightBlue!30}{1,2,3}
    \rowcolors{3}{MidnightBlue!10}{}
\Body
    \hline
    \Block{3-1}{text3} & \Block{1-2}{\textbf{test1}} && \Block{1-2}{\textbf{test2}} \\ 
    \Hline
    & \Block{2-1}{test1\\test} & \Block{2-1}{test2\\test}  & \Block{2-1}{test1\\test} & \Block{2-1}{test2\\test} \\ \\
    \hline 
    test & test & test & test & test \\
    test & test & test & test & test \\
    \hline
\end{NiceTabular}
\end{table}

\end{document}

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

Output of the above code

2
  • Can you explain how exactly I could use this package? I am using Overleaf.
    – NickG
    Commented Jun 18, 2021 at 17:12
  • Overleaf has not the latest version of nicematrix. You should upload the latest version of the file nicematrix.sty in the repertory of your Overleaf project. You can find that file on the SVN server of TeXLive: www.tug.org/svn/texlive/trunk/Master/texmf-dist/tex/latex/nicematrix/nicematrix.sty Commented Jun 18, 2021 at 18:06

You must log in to answer this question.

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