12

Possible Duplicate:
How to add a forced line break inside a table cell

I would like to write the header of a column on multiple line. I tried with this commands but it doesn't work:

\begin{tabular}{|c|l|l|l|l|l|l|}
\hline \\
$\alpha$ 
& \multicolumn{1}{|c|}{GallusGallus \\ CC \\ t = 104}
& \multicolumn{1}{|c|}{GallusGallus \\ MF \\ t = 124}
& \multicolumn{1}{|c|}{GallusGallus \\ BP \\ t = 110}
& \multicolumn{1}{|c|}{BosTaurus \\ CC \\ t = 99}
& \multicolumn{1}{|c|}{BosTaurus \\ MF \\ t = 217}
& \multicolumn{1}{|c|}{BosTaurus \\ BP \\ t = 205}
\end{tabular}

How can I fix?

user12818
  • 399

1 Answers1

27

You can use P{<width>}{<contents>} instead of using c column. In p (paragraph) column, usual \centering can be used to center the contents.

\documentclass{article}

\begin{document}
\begin{tabular}{|c|l|}
\hline 
$\alpha$
& \multicolumn{1}{|p{3cm}|}{\centering GallusGallus \\ CC \\ t = 104}\\\hline
\end{tabular}
\end{document}

enter image description here

Your full example will be:

\documentclass{article}
\usepackage[margin=2.5cm]{geometry}
\begin{document}
\noindent
\begin{tabular}{|c|l|l|l|l|l|l|}
\hline 
$\alpha$
& \multicolumn{1}{|p{2cm}|}{\centering GallusGallus \\ CC \\ t = 104}
& \multicolumn{1}{|p{2cm}|}{\centering GallusGallus \\ MF \\ t = 124}
& \multicolumn{1}{|p{2cm}|}{\centering GallusGallus \\ BP \\ t = 110}
& \multicolumn{1}{|p{2cm}|}{\centering BosTaurus \\ CC \\ t = 99}
& \multicolumn{1}{|p{2cm}|}{\centering BosTaurus \\ MF \\ t = 217}
& \multicolumn{1}{|p{2cm}|}{\centering BosTaurus \\ BP \\ t = 205}\\\hline
\end{tabular}
\end{document}

enter image description here

  • 5
    Why does removing \centering cause all sorts of errors? – Cyrille Mar 16 '15 at 11:53
  • @Cyrille What sort of error do you get? –  Mar 16 '15 at 12:49
  • It creates the PDF fine with the centering. I remove \centering and run again and get the following repeated a ~hundred times until a fatal error occurs: Missing } inserted.<inserted text>} ...|p{2cm}|}{ GallusGallus \\ CC \\ t = 104} and Extra }, or forgotten \endgroup.<recently read> \egroup ...|p{2cm}|}{ GallusGallus \\ CC \\ t = 104} – Cyrille Mar 17 '15 at 14:06
  • @Cyrille It compiles fine for me after removing \centering. –  Mar 17 '15 at 14:26
  • That's what I would have expected... Hmm oh well. A bug perhaps. Using a OS X 10.10.1 for the record. I will update Tex... Thanks! – Cyrille Mar 18 '15 at 13:46
  • 3
    @Cyrille I just want to confirm that I have the same issue on my mac, I can't remove the \centering. – Barth May 04 '15 at 10:30
  • @Cyrille, I got the same problem on Windows 7, using TexMaker. – Jorge V Oct 25 '15 at 16:02
  • How can you shift \alpha down to the 3rd row? \ does not work. – wjktrs Mar 18 '24 at 14:23