1

When I tried to add color to the cells to differentiate concavity points up from down, the text in the cells moved down versus the cells with no color added. What can I do to keep all cells text at the same level?

\documentclass[12pt,table]{report}
\usepackage{xcolor}
\usepackage{mathtools}

\usepackage{longtable,tabu}

\setlength{\extrarowheight}{4pt}

\begin{document}

\bigbreak
\begin{longtabu}{
|p{\dimexpr.25\linewidth-2\tabcolsep-1.3333\arrayrulewidth}
|p{\dimexpr.15\linewidth-2\tabcolsep-1.3333\arrayrulewidth}
|p{\dimexpr.25\linewidth-2\tabcolsep-1.3333\arrayrulewidth}
|} %\textwidth
\hline
\centering \boldmath $\text{Lable on Sketch}$ & \centering \boldmath  $x$ & \centering \textbf{Concavity} \tabularnewline\hline 
\centering $x_{0}$ & \centering $0$ & \centering \color{red}Concave up\\\hline  
\centering $x_{0}$ & \centering $0$ & \centering Concave up\\\hline 
\end{longtabu}

\end{document}

enter image description here

  • 2
    Consider using \textcolor{red}{Concave up}. – Werner Aug 25 '17 at 0:44
  • 2
    Offtopic: you may add '>{\centering}' before every 'p' of column type to avoid so many '\centering' in elements – koleygr Aug 25 '17 at 0:49
1

Putting a \leavevmode before the \color command solves this.

As can be gathered from this answer, TeX puts a \special (or pdftex color primitive which is equivalent) which inserts the commands to switch the color. However, unlike a font change this is an actual item on the vertical list. And thus it contributes to the space. So, it's normally better to try to get the color switch into horizontal mode.

\documentclass[12pt,table]{report}
\usepackage{xcolor}
\usepackage{mathtools}

\usepackage{longtable,tabu}

\setlength{\extrarowheight}{4pt}

\begin{document}

\bigbreak
\begin{longtabu}{
    |p{\dimexpr.25\linewidth-2\tabcolsep-1.3333\arrayrulewidth}
    |p{\dimexpr.15\linewidth-2\tabcolsep-1.3333\arrayrulewidth}
    |p{\dimexpr.25\linewidth-2\tabcolsep-1.3333\arrayrulewidth}
    |} %\textwidth
  \hline
  \centering \boldmath $\text{Lable on Sketch}$ & \centering \boldmath  $x$ & \centering \textbf{Concavity} \tabularnewline\hline 
  \centering $x_{0}$ & \centering $0$ & \centering \leavevmode\color{red} Concave up\\\hline  
  \centering $x_{0}$ & \centering $0$ & \centering Concave up\\\hline 
\end{longtabu}

\end{document}

enter image description here

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