Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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.

share|improve this question

marked as duplicate by David Carlisle, lockstep, Martin Schröder, Andrew Swann, Marco Daniel Oct 22 '12 at 9:52

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

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 7:44

1 Answer 1

up vote 2 down vote accepted

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

share|improve this answer

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