2

Enthusiastically using the alternate table row coloring feature in xcolor (which I discovered here on TeXSE, as many more most useful things), I stumbled on an annoying phenomenon: the code

\documentclass{amsart}

\usepackage[table]{xcolor}

\rowcolors{2}{gray!10}{white}

\begin{document}
\begin{tabular}{l|r}
left head&right head\\
\hline
\hline
cell&cell\\
\hline
L\hfill R&cell\\
\hline
cell&cell\\
\hline
cell&cell\\
cell&cell
\end{tabular}
\end{document}

produces

enter image description here

That annoying blind spot is, doubtlessly, caused by the \hfill, but why? Can I get rid of it? I don't mind splitting that particular cell into two if you tell me how. Making extra column is not an option since I only need it occasionally in very few cells.

4

enter image description here

If you use fill glue the total must be 0fill see the paragraph at the top of page 10 of texdoc colortbl.

\documentclass{amsart}

\usepackage[table]{xcolor}

\rowcolors{2}{gray!10}{white}

\begin{document}
\begin{tabular}{l|r}
left head&right head\\
\hline
\hline
cell&cell\\
\hline
L\hfill R\hspace{-\fill}\mbox{}&cell\\
\hline
cell&cell\\
\hline
cell&cell\\
cell&cell
\end{tabular}
\end{document}
3

Here is a way to construct that table with {NiceTabular} of nicematrix.

You will have a perfect ouput in the PDF viewers. The rules won't seem to vanish in some PDF viewers (such as Adobe Reader) as some levels of zoom.

\documentclass{amsart}
\usepackage{nicematrix}

\begin{document}
\begin{NiceTabular}{l|r}
\CodeBefore
  \rowcolors{2}{gray!10}{}
\Body
left head&right head\\
\hline
\hline
cell&cell\\
\hline
L \Block[r]{}{R}&cell\\
\hline
cell&cell\\
\hline
cell&cell\\
cell&cell
\end{NiceTabular}
\end{document}

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

Output of the above code

2

Try to put

\begin{tabular}{@{}ll@{}}L&R\end{tabular}

Instead of the cell with \hfill (you can build a macro easily)

5

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.