Changing the text color for a cell does change alignment [duplicate]

If i color the text of a table cell, the text gets aligned wrong.

MWE:

\documentclass[10pt, handout]{beamer}

\usepackage{tabulary}
\usepackage{xcolor}

\begin{document}
\begin{frame}{Test}
\begin{tabulary}{\textwidth}{LLLL}
test & test & test & test \\
test & \color{red}test & test & test \\
\end{tabulary}
\end{frame}
\end{document}


I want to use it in a way like this:

\newcommand{\highlight}{\color{black}\cellcolor{red}}

\begin{tabulary}{\textwidth}{LLLL}
test & test & test & test \\
test & \highlight test & test & test \\
\end{tabulary}

• Use \textcolor{red}{test} rather -- it works then.
– user31729
Sep 5, 2016 at 7:42

Either use \leavevmode or \textcolor

\documentclass[10pt, handout]{beamer}

\usepackage{tabulary}
\usepackage{xcolor}

\begin{document}
\begin{frame}{Test}
\begin{tabulary}{\textwidth}{LLLL}
test & test & test & test \\
test & \leavevmode\color{red}test & \textcolor{red}{test} & test \\
\end{tabulary}
\end{frame}
\end{document}


• \leavemode does what i need. Could you explain what's the problem here and why \leavemode does solve it? Sep 5, 2016 at 7:47