5

The following MWE :

\documentclass[10pt]{article}
\usepackage[french]{babel}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}


\usepackage{color}
\usepackage{array,float}

\begin{document}
    \begin{tabular}{|*{3}{>{\centering}p{1cm}|}}
        \hline \color{red}A&B&C\tabularnewline \hline
    \end{tabular}

    \begin{tabular}{|*{3}{>{\centering}m{1cm}|}}
        \hline \color{blue}A&B&C\tabularnewline \hline
    \end{tabular}

    Some blablah...
\end{document}

gives me :

enter image description here

The blue color continues after the cell, and even after the tabular !

I know that I can basically solve the problem with braces around

\color{blue}A

but I want to understand why, if I use "m" parameter instead of "p" in tabular, \color has this strange behaviour... (Otherwise, why, in the first tabular, cells are higher and A in the bottom of his cell ?)

4

See the footnote on page 6 of the color package documentation.

You can use \leavevmode\color... to avoid the problem.

If you add \color in vertical mode before the paragraph starts then instead of being at the start of the first line the color whatsit node comes above the first line. a p column aligns on the first item so it aligns on that node not the baseline of the first row of text.


You can address the colour leaking by adding explicit {} to keep the colour in the cell

\documentclass[10pt]{article}

\usepackage{color}
\usepackage{array}%[=2016-10-06]

\begin{document}
    \begin{tabular}{|*{3}{>{\centering}p{1cm}|}}
        \hline \leavevmode\color{red}A&B&C\tabularnewline \hline
    \end{tabular}

    \begin{tabular}{|*{3}{>{\centering}m{1cm}|}}
        \hline {\leavevmode\color{blue}A}&B&C\tabularnewline \hline
    \end{tabular}

    Some blablah...
\end{document}

But that should not be needed, if you use the previous version of array by uncommenting the optional argument then it works without the `{. I'll raise an issue on github about that.

  • it should be corrected by now in the LaTeX sources and will show up with the next release. – Frank Mittelbach Sep 18 '18 at 17:41

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.