1

Possible Duplicate:
Color changes cell height in tabular

The following latex table contains two rows. The rows are identical, except for the greeen color in the first cell in the second row:

\begin{tabularx}{\textwidth}{ |X|X|X|X| }
  \hline
  \texttt{re.match('go.', 'gob')}                       & 2  & 3  & 4  \\
  \hline
  \color{ForestGreen}{\texttt{re.match('go.', 'gob')}}  & 2  & 3  & 4  \\
  \hline
\end{tabularx}

The color appears to add some padding space above it: enter image description here

When the color is removed, the spacing is normal again:

enter image description here

Why does cell color affect table spacing?

Original file in github.

  • 1
    I am not sure about the padding that the command \color{<color>}{<text>} does but \textcolor{ForestGreen}{\texttt{re.match('go.', 'gob')}} seems to work. – hpesoj626 Oct 22 '12 at 07:44

1 Answers1

2

I don't know if this really answers your question. But if you want to make the table behave normally with text color then you can use \textcolor{ForestGreen}{\texttt{re.match('go.', 'gob')}}. My guess is that with the \color command, the color is extended to the whole box containing your text. Try for instance \colorbox command as you can see in the attached picture.

\documentclass[10pt]{article}

\usepackage[margin=1in]{geometry}
\usepackage[usenames,dvipsnames,svgnames,table]{xcolor}
\usepackage{tabularx}

\begin{document}

\raggedright
\footnotesize

\section{Meta characters}

\begin{tabularx}{\textwidth}{ |X|X|X|X| }
  \hline
  \texttt{re.match('go.', 'gob')} & 2 & 3 & 4 \\
  \hline
  \textcolor{ForestGreen}{\texttt{re.match('go.', 'gob')}} & 2 & 3 & 4 \\
  \hline
  \color{ForestGreen}{\texttt{re.match('go.', 'gob')}} & 2 & 3 & 4 \\
  \hline
  \colorbox{ForestGreen}{\texttt{re.match('go.', 'gob')}} & 2 & 3 & 4 \\
  \hline
\end{tabularx}

\end{document}

enter image description here

David Carlisle
  • 757,742
hpesoj626
  • 17,282