\documentclass{article}
\usepackage{array}
\begin{document}
\begin{tabular}{| >{\centering}p{2.5cm} | >{\centering}p{0.5cm} | >{\centering}p{2.5cm} |>{\centering}p{2.5cm} |>{\centering}p{2.5cm} |>{\centering}p{2.5cm} |}
\hline
Abc & Bcd & A long cell with text that wraps around and is centered & long cell with text & AAAlong cell with text that wraps around and is centered & SSSlong cell with text that wraps around and is centered \\
1 & 3 & qw & qe & sad &11\\
\hline
\end{tabular}
\end{document}
\centering
changes the definition of \\
which breaks inside tabluar
s and array
s. You need to add \arraybackslash
afterwards to correct this. You also should define a new column type if you need this more often:
\documentclass{article}
\usepackage{array}
\newcolumntype{C}[1]{>{\centering\arraybackslash}p{#1}}
\begin{document}
\begin{tabular}{| C{2.5cm} | C{0.5cm} | C{2.5cm} |C{2.5cm} |C{2.5cm} |C{2.5cm} |}
\hline
Abc & Bcd & A long cell with text that wraps around and is centered & long cell with text & AAAlong cell with text that wraps around and is centered & SSSlong cell with text that wraps around and is centered \\
1 & 3 & qw & qe & sad &11\\
\hline
\end{tabular}
\end{document}
See the related answer to Center column with specifying width in table (tabular enviroment)? for advanced declarations which support line-breaks and hyphenation of the first word.
-
1For narrow columns (such as the second one in the example code) it would be a good idea to add
\hspace{0pt}
to the column definition, to allow hyphenation of the first word. – Gonzalo Medina May 23 '11 at 16:42 -
Dear Martin. When I ran it, one error appeared: úndefined control sequence'for command ''newcolumntype'' – Strong May 23 '11 at 20:52
-
@Strong: It works for me.
\newcolumntype
is defined by thearray
package. – Martin Scharrer♦ May 23 '11 at 20:58
\centering
inside table column definition results in error message")? – lockstep May 23 '11 at 16:40\\
. – lockstep May 23 '11 at 16:43