http://en.wikibooks.org/wiki/LaTeX/Tables contains an example on how to do text wrapping in tables by using p{5cm}:
\begin{center}
\begin{tabular}{ | l | l | l | p{5cm} |}
\hline
Day & Min Temp & Max Temp & Summary \\ \hline
Monday & 11C & 22C & A clear day with lots of sunshine.
However, the strong breeze will bring down the temperatures. \\ \hline
Tuesday & 9C & 19C & Cloudy with rain, across many northern regions. Clear spells
across most of Scotland and Northern Ireland,
but rain reaching the far northwest. \\ \hline
Wednesday & 10C & 21C & Rain will still linger for the morning.
Conditions will improve by early afternoon and continue
throughout the evening. \\
\hline
\end{tabular}
\end{center}
How do I get the contents of the cells in that column to be centered?
Here is what I have tried:
\begin{table}[h]
\centering
\resizebox{\textwidth}{!}{%
\begin{tabular}{p{20cm}}
\rowcolor[HTML]{3166FF}
\pbox{
\Huge Line 1 of my long title
\\ \Huge Line2 of my long title} \\ \hline
\huge Sub title
\end{tabular}
}
\end{table}
I want to achieve something like this from Word:
I have gotten closer, but it still doesn't look professional in LaTeX:
\begin{table}[h]
\centering
\resizebox{\textwidth}{!}{%
\begin{tabular}{p{13cm}}
\rowcolor[HTML]{3166FF}
\centering \Huge This is a very long title that spans multiple lines \\ \hline
\centering \huge Sub title
\end{tabular}
}
\end{table}
Best Answer
Use
\newcolumntype
fromarray
package and define a style, sayC
with automatic wrapping and centering.The principle way to define a new column type to use one of existing ones, i.e.
l
,r
,p
orc
.The syntax is (with an argument)
\newcolumntype{Y}[1]{>{some stuff before\arraybackslash}Z{#1}}
, where Y stands for the new letter,Z
is one of already existing types.Just before
\arraybackslash
, basically anything can be inserted, say a\centering
, so this will be used inside the Z - type.Edit Some propositions to improve the look of the table.