Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

The following example shows the problem using the \b command for the "bar-under" accent: it seems to interact in an unexpected way with \rowcolor. Uncommenting the appropriate \renewcommand line, the example shows also a bad interaction with \c (for the "cedilla"), and \d (for the "dot-under" accent):

\documentclass{article}
\usepackage[table]{xcolor}

\newcommand*\CRow[1]{\rowcolor{blue!30}\b#1\\}
%\renewcommand*\CRow[1]{\rowcolor{blue!30}\c#1\\}% uncomment for cedilla
%\renewcommand*\CRow[1]{\rowcolor{blue!30}\d#1\\}% uncomment for dot-under

\begin{document}

\begin{tabular}{c}
  \CRow{a}
  \CRow{b}
  \CRow{c}
  \CRow{d}
  \CRow{e}
  \CRow{f}
  \CRow{g}
  \CRow{h}
  \CRow{i}
  \CRow{j}
  \CRow{k}
  \CRow{l}
  \CRow{m}
  \CRow{n}
  \CRow{o}
  \CRow{p}
  \CRow{q}
  \CRow{r}
  \CRow{s}
  \CRow{t}
  \CRow{u}
  \CRow{v}
  \CRow{w}
  \CRow{x}
  \CRow{y}
  \CRow{z}
\end{tabular}

\end{document}

The output:

enter image description here

What is causing the problem and how to avoid it?

share|improve this question
    
I wonder whether has something to do with David Carlisle's comment in the colortbl package documentation regarding \rowcolor. Moreover, he refers to \rowcolor as a "mechanism"... –  Werner Aug 22 '11 at 4:49

2 Answers 2

up vote 6 down vote accepted
+50

As egreg has pointed out in a comment to the answer of Alan Munn the colortbl package uses \everycr or, more precisely, an alias \CT@everycr to insert a specific token list after every \cr and effective \crcr:

\let\CT@everycr\everycr
\newtoks\everycr
\CT@everycr{\noalign{\global\let\CT@row@color\relax}\the\everycr}

In essence, this configuration causes \rowcolor to set the background colour for the current row, but not for subsequent ones.

The macro \b and friends are based on \ialign which is defined in the LaTeX kernel:

\def\ialign{\everycr{}\tabskip\z@skip\halign}

Obviously, \ialign provides for the case that \everycr is used; it does, however, not provide for the case that \CT@everycr is used instead of \everycr.

As a result, if \b, \c or \d appear in a row initiated by \rowcolor they might implicitly reset the background colour before the end of the row. You can prevent this by means of an adequate new column type:

\documentclass{article}

\usepackage[table]{xcolor}

\makeatletter

\newcolumntype{-}{%
  >{\CT@everycr{}}%
}

\makeatother

\newcommand*{\CRow}[1]{%
  \rowcolor{blue!30}\b#1&\c#1&\d#1\\%
}

\begin{document}

\begin{tabular}{-c-c-c}
  \CRow{a}
  \CRow{b}
  \CRow{c}
  \CRow{d}
  \CRow{e}
  \CRow{f}
  \CRow{g}
  \CRow{h}
  \CRow{i}
  \CRow{j}
  \CRow{k}
  \CRow{l}
  \CRow{m}
  \CRow{n}
  \CRow{o}
  \CRow{p}
  \CRow{q}
  \CRow{r}
  \CRow{s}
  \CRow{t}
  \CRow{u}
  \CRow{v}
  \CRow{w}
  \CRow{x}
  \CRow{y}
  \CRow{z}
\end{tabular}

\end{document}

The resulting output is:

share|improve this answer
    
Thank you for the explanation on the cause of the problem and for providing a solution. –  Gonzalo Medina Aug 25 '11 at 19:55

Here's a partial answer, and a workaround. It's somehow dependent on the font and the encoding. If you load fontenc with the T1 encoding, and use \c you one more correct glyph: the t, although it has no effect on the \b or \d. The following quote from TeX by Topic is also probably relevant (p.47)

No genuine under-accents exist in TeX. They are implemented as low placed over-accents. A way of handling them more correctly would be to write a macro that measures the following character, and raises or drops the accent accordingly. The cedilla macro, \c, in plain TeX does something along these lines. However, it does not drop the accent for characters with descenders.

I'm not sure how this interacts with the \rowcolor command, though.

Notice that in Plain TeX if you do:

\setbox0=\hbox{\c c}
\showbox0

you get:

> \box0=
\hbox(4.30554+1.70137)x4.44444
.\kern 0.0 (for accent)
.\tenrm ^^X
.\kern -4.44444 (for accent)
.\tenrm c

But if you do one of the characters that doesn't work, you get:

\setbox0=\hbox{\c t}
\showbox0

> \box0=
\hbox(6.15079+1.70137)x3.8889
.\vbox(6.15079+1.70137)x3.8889
..\hbox(6.15079+0.0)x3.8889
...\glue(\tabskip) 0.0
...\hbox(6.15079+0.0)x3.8889 []
...\glue(\tabskip) 0.0
..\glue(\baselineskip) 0.0
..\hbox(0.0+1.70137)x3.8889
...\glue(\tabskip) 0.0
...\hbox(0.0+1.70137)x3.8889, glue set 999.72223fill []
...\glue(\tabskip) 0.0

As a workaround, you can use XeLaTeX (doesn't work with LuaLaTeX, for some reason.) The effect is still font-dependent, however. If you just use the default font with XeLaTeX (Latin Modern) you get a different effect than when you use it with pdfLaTeX: none of the cells are black, but some of the glyphs are completely missing (b, h, k, l, n, r and z). Very odd. Notice, however, that it is these glyphs that also show a slightly smaller underbar in the XeLaTeX output below. I don't think this is an accident.

% !TEX TS-program = XeLaTeX

\documentclass{article}
\usepackage[table]{xcolor}
\usepackage{fontspec}
\setmainfont[Ligatures=TeX]{Linux Libertine}
\newcommand*\CRow[1]{\rowcolor{blue!30}\b#1\\}
%\renewcommand*\CRow[1]{\rowcolor{blue!30}\c#1\\}% uncomment for cedilla
%\renewcommand*\CRow[1]{\rowcolor{blue!30}\d#1\\}% uncomment for dot-under

\begin{document}

\begin{tabular}{c}
  \CRow{a}
  \CRow{b}
  \CRow{c}
  \CRow{d}
  \CRow{e}
  \CRow{f}
  \CRow{g}
  \CRow{h}
  \CRow{i}
  \CRow{j}
  \CRow{k}
  \CRow{l}
  \CRow{m}
  \CRow{n}
  \CRow{o}
  \CRow{p}
  \CRow{q}
  \CRow{r}
  \CRow{s}
  \CRow{t}
  \CRow{u}
  \CRow{v}
  \CRow{w}
  \CRow{x}
  \CRow{y}
  \CRow{z}
\end{tabular}

\end{document}

output of code

Alternatively, you can use the tipa package (without XeLaTeX) and use \textipa{\b a} etc.

share|improve this answer
    
Alan, thank you for the answer and for the workaround. I'll start a bounty to see if someone can explain why there's a bad interaction with \rowcolor. –  Gonzalo Medina Aug 22 '11 at 21:05
    
@Gonzalo That seems like a good idea. Maybe my answer will help those with more knowledge (and time) than me actually explain the effect. –  Alan Munn Aug 22 '11 at 21:16
    
The problem seems to be in the fact that \b, \c and \d use \halign and colortbl plays with \everycr. One can say \cellcolor{...} for cells with those "accents". –  egreg Aug 23 '11 at 15:17

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.