davidcarlisle / dpctex

Assorted TeX packages
93 stars 30 forks source link

`colortbl`: In empty cells with `p{…}` column spec, `\cellcolor` doesn't color the whole cell #51

Closed mxmerz closed 2 months ago

mxmerz commented 2 months ago

I have a calendar document that I build every day where I color cells with \cellcolor - today, all of the empty cells looked really weird, see the following minimal working example:

\documentclass[border=.2cm]{standalone}

\usepackage{xcolor}
\usepackage{colortbl}

\begin{document}

  \begin{tabular}{|p{4cm}|c|}
    \hline
    \multicolumn{2}{|l|}{
      \cellcolor{blue!20}
      Die Hintergrundfarbe der nächsten Zelle ist kaputt:
    } \\
    \cellcolor{red!40} &
    \cellcolor{red!40} \\
    \multicolumn{2}{|l|}{
      \cellcolor{blue!20}
      Mit \texttt{\textbackslash hfill} geht es:
    } \\
    \cellcolor{orange!40} \hfill &
    \cellcolor{orange!40} \hfill \\
    \multicolumn{2}{|l|}{
      \cellcolor{blue!20}
      Mit anderem Inhalt auch:
    } \\
    \cellcolor{green!40} hallo &
    \cellcolor{green!40} hallo \\ \hline
  \end{tabular}

\end{document}

image

I assume that this is due to a recent update to colortbl?

davidcarlisle commented 2 months ago

I assume that this is due to a recent update to colortbl?

well probably the previous update to array (prior to the the recent colortbl update it would not produce any table at all)

See the issuse here (reported on tabularx but really on array)

https://github.com/latex3/latex2e/issues/1372

@FrankMittelbach 's fix there seems to fix your example, could you test on your real document and report back, sorry about the inconvenience

\documentclass[border=.2cm]{standalone}

\usepackage{xcolor}
\usepackage{colortbl}
\makeatletter
\def\@finalstrut#1{%
  \unskip
  \ifhmode \nobreak 
%  \vrule
  \else
    \ifdim \prevdepth=-\@m\p@
    \else
      \vskip-\prevdepth
    \fi   
\vskip-\baselineskip  %new
%    \hrule
  \fi
  \vrule %new
  \@width\z@\@height\z@\@depth\dp#1}
\makeatother

\begin{document}

  \begin{tabular}{|p{4cm}|c|}
    \hline
    \multicolumn{2}{|l|}{
      \cellcolor{blue!20}
      Die Hintergrundfarbe der nächsten Zelle ist kaputt:
    } \\
    \cellcolor{red!40} &
    \cellcolor{red!40} \\
    \multicolumn{2}{|l|}{
      \cellcolor{blue!20}
      Mit \texttt{\textbackslash hfill} geht es:
    } \\
    \cellcolor{orange!40} \hfill &
    \cellcolor{orange!40} \hfill \\
    \multicolumn{2}{|l|}{
      \cellcolor{blue!20}
      Mit anderem Inhalt auch:
    } \\
    \cellcolor{green!40} hallo &
    \cellcolor{green!40} hallo \\ \hline
  \end{tabular}

\end{document}

image

mxmerz commented 2 months ago

Wow, I would never have found that latex2e issue! 😅 Yes, that snippet fixes it!

davidcarlisle commented 2 months ago

@mxmerz thanks for confirming, I guess we will fix this in array package then arrange a tools update (tools collection normally just gets updated when latex does but we have released separate updates for that before). Leave this open and I'll ping here once we decide where this should get fixed

FrankMittelbach commented 2 months ago

Wow, I would never have found that latex2e issue! 😅 Yes, that snippet fixes it!

wasn't that difficult for me since I made the blunder not that long ago, so I did know where to look :-)

mxmerz commented 2 months ago

Updating to the current version on CTAN with tlmgr solves this problem for me :) Thanks a lot to both of you!