# tabularx+xcolor \rowcolor extends past page width

EDIT: I'm using this template: PoPETs (Sciendo). This is important for the failure.

Here's some simple code to demonstrate which uses the dgruyter_NEW package from the above template:

\documentclass[USenglish,oneside,twocolumn]{article}
\usepackage[big]{dgruyter_NEW}
\usepackage{pifont}
\usepackage{amsfonts}
\usepackage[table]{xcolor}
\usepackage{booktabs,array}
\usepackage{pgfplotstable}
\pgfplotsset{compat=1.8}

\begin{document}
\begin{table*}[t]
\begin{tabularx}{\linewidth}{l}
\end{tabularx}
\end{table*}
\end{document}


The result:

For reference, I am using this template: PoPETs (Sciendo). Any ideas?

• Welcome! Could you please post a complete example, which starts with \documentclass, ends with \end{document} and can be compiled? And explain why you put \centering after \end{tabularx}?
– user194703
Jun 10, 2020 at 2:22
• Sure, I have done so. The \centering does not seem to have affected the result, I believe it was for a caption that I removed. Jun 10, 2020 at 2:56
• Thanks! The problem is that on my installation the package dgruyter_NEW is not known. If I replace it by tabularx, I can't reproduce the error.
– user194703
Jun 10, 2020 at 3:01
• Thanks for looking into it! Yep, that package comes from the conference template. I have narrowed the issue to that template itself, but I haven't gotten further. Jun 10, 2020 at 3:40
• OK, then you probably may want to provide a link to the template, maybe a good soul will dig through it. (There is a general misconception that every .sty file is written by a LaTeX goddess. Unfortunately this is very far from the truth, and in particular conference templates often leave a lot room for improvement.)
– user194703
Jun 10, 2020 at 3:42

(My answer gives the same suggestion with @shaananc's answer, but with a complete example accompanied with some explanations.)

dgruyter_NEW.sty patches many internal macros including \@array. As @shaananc pointed, two \expandafter\ifx\d@llarbegin\begingroup\hskip-\col@sep\fi is added to the definition of \@preamble, which as I understand is used to remove the space before first column and after last column in a tabular. It seems this change is not compatible with \rowcolor.

In the following example, those two lines are removed from the definition of \@array (by \xpatchcmd from xpatch command), and tabular examples are given to illustrate what changed and how to restore the effect of dgruyter_NEW.sty manually.

\documentclass[USenglish,oneside,twocolumn]{article}
\usepackage[big]{dgruyter_NEW}
\usepackage{pifont}
\usepackage{amsfonts}
\usepackage[table]{xcolor}
\usepackage{booktabs,array}
\usepackage{pgfplotstable}
\pgfplotsset{compat=1.8}

\usepackage{xpatch}
\makeatletter
\xpatchcmd\@array
{\expandafter\ifx\d@llarbegin\begingroup\hskip-\col@sep\fi}
{}
{}{\fail}
\xpatchcmd\@array
{\expandafter\ifx\d@llarbegin\begingroup\hskip-\col@sep\fi}
{}
{}{\fail}
\makeatother

\begin{document}

\subsection*{With \texttt{\string\rowcolor}}
\begin{tabularx}{\linewidth}{c}
B \\
C \\
\end{tabularx}

\subsection*{Without \texttt{\string\rowcolor}}
\begin{tabular}{c}
A \\
B \\
C \\
\end{tabular}\smallskip

Note the space of width \verb|\tabcolsep| is inserted before first column and after last column by default (again).

\subsection*{Without \texttt{\string\rowcolor}, use \texttt{@\{\}} to remove  that space}
\begin{tabular}{@{}c@{}}
A \\
B \\
C \\
\end{tabular}\smallskip

Note this emulates the original effect of \verb|dgruyter_NEW.sty|.

\end{document}


This block of code in the template is causing the issues:

\def\@array[#1]#2{%
\@tempdima \ht \strutbox
\setbox \@arstrutbox \hbox{\vrule
\@height \arraystretch \@tempdima
\@depth \arraystretch \dp \strutbox
\@width \z@}%
\begingroup
\@mkpream{#2}%
\xdef\@preamble{\noexpand \ialign \@halignto
\bgroup
\expandafter\ifx\d@llarbegin\begingroup\hskip-\col@sep\fi
\@arstrut \@preamble
\expandafter\ifx\d@llarbegin\begingroup\hskip-\col@sep\fi
\tabskip \z@ \cr}%
\endgroup
\@arrayleft
\if #1t\vtop \else \if#1b\vbox \else \vcenter \fi \fi
\bgroup
\let \@sharp ##\let \protect \relax
\lineskip \z@
\baselineskip \z@
\m@th
\let\\\@arraycr \let\tabularnewline\\\let\par\@empty \@preamble}


It is used to modify the box sizes for the template, but I don't know enough to explain what the precise problem is or to provide a fix.

EDIT: My suspicion is that the lengths here aren't what they should be \expandafter\ifx\d@llarbegin\begingroup\hskip-\col@sep\fi