3

Is tabularx compatible with xcolor? I did the following:

enter image description here

\documentclass{memoir}
\usepackage[svgnames,hyperref,]{xcolor} % colors for hyperref
\begin{document}
  \begin{tabularx}{1.00\linewidth}{X} \toprule
  a
  \\
  b
  \\
  {\color{red}c} \\
  d
  \\
  e
  \\
\bottomrule
\end{tabularx}
\end{document}

But "c" is displaced so that it takes two rows. Changing the column type to l fixes it.

Is there an easy fix to making xcolor work with tabularx?

1
  • 1
    Try using \textcolor{red}{c} instead.
    – Werner
    Commented Apr 16, 2014 at 20:09

1 Answer 1

7

Columns with column type p and X that is based on p are implented via a \vtop, which is a \vbox, but aligned to the top baseline. \color does not start a paragraph, but it creates a whatsit (\special). Because of the vertical mode, it becomes the first element in the \vtop. Also the tabular environments add struts, therefore the cells in a row have at least the height of the strut.

You can avoid this by starting a paragraph:

  • implicit by \textcolor{red}{c} or

  • explicit with \leavemode{\color{red}c}

1
  • Great, thank you! It's great that there is a community of people who understand these details, but I wonder if these details are really necessary for good typesetting…
    – Neil G
    Commented Apr 16, 2014 at 20:21

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .