# Centering does not appear to work in table

Hi I just can't get the text in row 3 to centre. Array package is loaded. Any help greatly appreciated.

\centering

\begin{tabular}{|c|m{5cm}|}
\hline
STATE & EVENT \\
\hline
The vase was broken &  \\
\hline
\multicolumn {2} {|c|} {The vase was \colorbox{red!50}{broken}}\\
\hline
& The vase was \colorbox{red!50}{broken} \newline by the dog \\
\hline
\end{tabular}

-
Are you meaning horizontally or vertically centered? – egreg Jul 3 '12 at 11:43

It will work, if you make the second column centered:

\documentclass{article}
\usepackage{amsmath,array,xcolor}

\begin{document}

\centering

\begin{tabular}{|c|>{\centering\arraybackslash}m{5cm}|}
\hline
STATE & EVENT \\
\hline
The vase was broken &  \\
\hline
\multicolumn{2}{|c|}{The vase was \colorbox{red!50}{broken}}\\
\hline
& The vase was \colorbox{red!50}{broken} \linebreak by the dog \\
\hline
\end{tabular}

\end{document}


Edit
Reposted the changed output

-
the last cell has no correct horizontally centered text. Compare it with using \linebreak instead of \newline – Herbert Jul 3 '12 at 11:51
Thank you, @Herbert \linebreak centers better. But why is the difference? I edited my answer – Peter Breitfeld Jul 3 '12 at 12:00
the first line in the last cell doesn't look centered; if you remove the space before \linebreak that should be adjusted. (by the way, this doesn't happen with tex live 2010, and the code in latex.ltx looks stable, so i'm not sure what happened here.) – barbara beeton Jul 3 '12 at 12:36
@Peter: You need different commands to end a line as you need different behaviours. E.g. \\  in a center environment is actually a \par so replacing it by a \newline is wrong. The best imho is to use the intended end-of-line command. In your case either remove the \arraybackslash, use \\  to end the center lines and \tabularnewline to end the tabular lines. Or store the "center meaning" of \\  in a command before restoring the "tabular meaning": {\centering\let\cnewline\\\arraybackslash}  and then use this command. – Ulrike Fischer Jul 3 '12 at 12:44
@Peter; you should use package ragged2e and then only \Centering, then you can use \newline and also \\. However, as Ulrike already wrote, \tabularnewline makes more sense – Herbert Jul 3 '12 at 13:12