It appears that when using xcolor along with tabular, coloring the text of a cell inside a paragraph columns breaks its alignment:




\begin{tabular}{c p{5cm}}
    test1 & {\color{darktext} test2} \\
    test3 & test4 \\


Is this a bug or intended? Is there some alternative to doing this?

  • {\leavevmode\color{darktext} test2}. A number of LaTeX commands are not intended for use in vertical mode. Jan 5 '17 at 19:14
  • 3
    It is a documented feature, use \textcolor{darktext}{test2} Jan 5 '17 at 19:14

See the footnote on page 6 of grfguide (texdoc color).

A whatsit node such as a \color special if used in vertical mode will affect the alignment of the surrounding box.

You can avoid this by using \leavevmode\color{darktext} test2 or perhaps more naturally \textcolor{darktext}{test2} (\textcolor adds the \leavevmode internally for exactly this issue). In either case these versions cause the colour to start in the first line of the paragraph not before the paragraph, which means that the first item in the box for the table cell is the first line of the paragraph, so the alignment point for the box is not affected, and is still the baseline of that line of text.

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.