1

I am trying to write a certain table on beamer, but there is a problem with the command \arrayrulecolor I cannot understand...

Here is the table in an article document class, how I want it to look like. (Some may object to my choice to use horizontal and vertical rules: but this is just a working example of the problem, my real table is hundreds of rows long, with at least a dozen columns and many, many multicolumns and multirows, and I think, and some people I discussed the table with agree, that the rules help a little bit.)

enter image description here

The code is as follows.

\documentclass[9pt,dvipsnames,table]{article}
 \usepackage{xcolor}
\usepackage[utf8]{inputenc}
\linespread{1.5}
\usepackage{graphicx}
%\usetheme{Frankfurt}
\usepackage{amsbsy}         
\usepackage{amscd}          
\usepackage{amsfonts}
\usepackage{amsmath}        
\usepackage{amssymb}        
\usepackage{amstext}        
\usepackage{amsthm}
\usepackage{multicol}
\usepackage{multirow}       
\usepackage{tikz-cd}
\usepackage{colortbl}
\usepackage{hhline}

\begin{document} %\begin{frame}{Title} \begin{table}[h] \centering \begin{tabular}{|c|c|c|} \hline Y & \cellcolor{red!15} & Y \\hhline{-{1}{>{\arrayrulecolor{red!15}}|-}{1}{>{\arrayrulecolor{black}}|-}} Y & \multirow{-2}{*}{\cellcolor{red!15}N} & Y\\hline \end{tabular} \end{table} %\end{frame} \end{document}

But, when I try to use exactly the same code on beamer, I get the following: notice the white line in the middle column, and the absence of a black line in the last.

enter image description here

The code is essentially the same, but I still post it below.

\documentclass[9pt,dvipsnames,table]{beamer}

\usepackage{xcolor} \usepackage[utf8]{inputenc} \linespread{1.5} \usepackage{graphicx} \usetheme{Frankfurt} \usepackage{amsbsy}
\usepackage{amscd}
\usepackage{amsfonts} \usepackage{amsmath}
\usepackage{amssymb}
\usepackage{amstext}
\usepackage{amsthm} \usepackage{multicol} \usepackage{multirow}
\usepackage{tikz-cd} \usepackage{colortbl} \usepackage{hhline}

\begin{document} \begin{frame}{Title} \begin{table}[h] \centering \begin{tabular}{|c|c|c|} \hline Y & \cellcolor{red!15} & Y \\hhline{-{1}{>{\arrayrulecolor{red!15}}|-}{1}{>{\arrayrulecolor{black}}|-}} Y & \multirow{-2}{*}{\cellcolor{red!15}N} & Y\\hline \end{tabular} \end{table} \end{frame} \end{document}

Honestly, I have no idea of what is the problem: I tried searching online for some known bug in the interplay between beamer and \arrayrulecolor, but nothing. I tried switching the order of the packages too, to no avail... I also removed every package I could, the ones above being the absolutely necessary for my document to work, but that did not help me either.

2 Answers2

2

As explained by David Carlisle in this question, the origin of the problem is an \unskip added by Beamer in the definition of the LaTeX command \reset@color.

If you want, here is a patch with a modification of \HH@loop. That command is a command of \hhline but it is redefined by \colortbl. That's why I do a modification of that redefinition. I have only added a \kern\z@ that will be gobbled by the \unskip.

\documentclass[9pt,dvipsnames,table]{beamer}
 \usepackage{xcolor}
\usepackage[utf8]{inputenc}
\linespread{1.5}
\usepackage{graphicx}
%\usetheme{Frankfurt}
\usepackage{amsbsy}         
\usepackage{amscd}          
\usepackage{amsfonts}
\usepackage{amsmath}        
\usepackage{amssymb}        
\usepackage{amstext}        
\usepackage{amsthm}
\usepackage{multicol}
\usepackage{multirow}       
\usepackage{tikz-cd}
\usepackage{colortbl}
\usepackage{hhline}

\begin{document}

\makeatletter

\def\HH@loop{% \ifx@tempb`\def\next##1{\the\toks@\cr}\else\let\next\HH@let \ifx@tempb|\if@tempswa \ifx\CT@drsc@\relax \HH@add{\hskip\doublerulesep}% \else \HH@add{{\CT@drsc@\vrule@width\doublerulesep}}% \fi \fi@tempswatrue \HH@add{{\CT@arc@\vline}}\else \ifx@tempb:\if@tempswa \ifx\CT@drsc@\relax \HH@add{\hskip\doublerulesep}% \else \HH@add{{\CT@drsc@\vrule@width\doublerulesep}}% \fi \fi@tempswatrue \HH@add{@tempc\HH@box\arrayrulewidth\arrayrulewidth@tempc}\else \ifx@tempb##\if@tempswa\HH@add{\hskip\doublerulesep}\fi@tempswatrue \HH@add{{\CT@arc@\vline\copy@ne@tempc\vline}}\else \ifx@tempb~@tempswafalse \if@firstamp@firstampfalse\else\HH@add{&\omit}\fi \ifx\CT@drsc@\relax \HH@add{\hfil}\else \HH@add{{% \CT@drsc@\leaders\hrule@height\HH@height\hfil}}% \fi \else \ifx@tempb-@tempswafalse \gdef\HH@height{\arrayrulewidth}% \if@firstamp@firstampfalse\else\HH@add{&\omit}\fi \HH@add{{% \CT@arc@\leaders\hrule@height\arrayrulewidth\hfil\kern\z@}}% \kern\z@ added \else \ifx@tempb=@tempswafalse \gdef\HH@height{\dimen\thr@@}% \if@firstamp@firstampfalse\else\HH@add{&\omit}\fi \HH@add {\rlap{\copy@ne}\leaders\copy@ne\hfil\llap{\copy@ne}}\else \ifx@tempb t\HH@add{% \def\HH@height{\dimen\thr@@}% \HH@box\doublerulesep\z@}@tempswafalse\else \ifx@tempb b\HH@add{% \def\HH@height{\dimen\thr@@}% \HH@box\z@\doublerulesep}@tempswafalse\else \ifx@tempb>\def\next##1##2{% \HH@add{% {\baselineskip\p@\relax ##2% \global\setbox@ne\HH@box\doublerulesep\doublerulesep}}% \HH@let!}\else \ifx@tempb@sptoken\let\next\HH@spacelet\else \PackageWarning{hhline}% {\meaning@tempb\space ignored in \noexpand\hhline argument% \MessageBreak}% \fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi \next}

\makeatother

\begin{frame}{Title} \begin{table}[h] \centering \begin{tabular}{|c|c|c|} \hline Y & \cellcolor{red!15} & Y \\hhline{-{1}{>{\arrayrulecolor{red!15}}|-}{1}{>{\arrayrulecolor{black}}|-}} Y & \multirow{-2}{*}{\cellcolor{red!15}N} & Y\\hline \end{tabular} \end{table} \end{frame} \end{document}

Output of the above code

By the way, I think that there is an error in your instruction \hhline.

You will have a better output with the following code :

\hhline{-|*{1}{>{\arrayrulecolor{red!15}}-}*{1}{>{\arrayrulecolor{black}}|-}}

Output of the above code

However, I recommend {NiceTabular} to construct such tables.

\documentclass[9pt,dvipsnames]{beamer}
\usepackage{nicematrix}
\linespread{1.5}

\begin{document}

\begin{frame}{Title}

\begin{center} \begin{NiceTabular}{ccc}[hvlines] Y & \Block[fill=red!15]{2-1}{N} & Y \ Y & & Y\ \end{NiceTabular} \end{center}

\end{frame}

\end{document}

Output of the above code

As you see, you will have a better output in the PDF viewers.

F. Pantigny
  • 40,250
  • That works, thank you very much! About the error in my \hhline instruction, you mean I should move | from *{1}{>{\arrayrulecolor{red!15}}|-} to just before that expression? – AnyDisplayName Apr 19 '23 at 07:13
  • Yes. The | should be before \arrayrulecolor{red!15} in order to have a small square black instead of red. – F. Pantigny Apr 19 '23 at 09:19
1

Welcome to TeX.SE! As suggested @samcarter_is_at_topanswers.xyz, use of the tabularray package can be solution:

\documentclass[9pt,dvipsnames,table]{beamer}
\usetheme{Frankfurt}
\usepackage{tabularray}

\begin{document} \begin{frame}{Title} \begin{table}[h] \centering \begin{tblr}{hlines, vlines, colspec = {c Q[c] c} } Y & \SetCell[r=2]{c,bg=red!15} N & Y \ Y & & Y \ Z & Z & Z \ \end{tblr} \end{table} \end{frame}

enter image description here

The same result you will get at use of the article document class.

Note: be aware, that beamer load some packages as are xcolor, graphicx, amsmath etc.

Zarko
  • 296,517
  • Thanks! Unfortunately my real table is extremely long, and rewriting it using tabularray would be very time consuming... I will wait a little longer for a solution using \arrayrulecolor, but will keep your answer in mind. – AnyDisplayName Apr 17 '23 at 12:30
  • @AnyDisplayName, changing from classic table to tabularray table is simple. Benefits are evident and worth for this effort (actually you only need to define table preambles and clean-up your table codes)., rewriting rules colors is quite demanding task ... but all is up to you – Zarko Apr 17 '23 at 12:48