[Tex/LaTex] text wrapping and vertical alignment of text in a table

tablesvertical alignmentwrap

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:

enter image description here

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}

enter image description here

Best Answer

Use \newcolumntype from array package and define a style, say C 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 or c.

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.

\documentclass{article}
\usepackage{siunitx}
\usepackage{booktabs}
\usepackage{array}
\newcolumntype{C}[1]{>{\centering\arraybackslash}p{#1}}



\begin{document}

\begin{center}

    \begin{tabular}{l*{2}{C{2cm}}C{5cm}}
      \multicolumn{4}{c}{ \large \textbf{ The good table...}} \tabularnewline[2ex]

      \toprule
    Day & Min Temp (\si{\degreeCelsius}) & Max Temp (\si{\degreeCelsius})  & Summary \tabularnewline 
    \midrule
    Monday & 11 & 22 & A clear day with lots of sunshine.  
    However, the strong breeze will bring down the temperatures. \tabularnewline[1ex]
    Tuesday & 9 & 19 & Cloudy with rain, across many northern regions. Clear spells
    across most of Scotland and Northern Ireland,
    but rain reaching the far northwest. \tabularnewline[1ex]
    Wednesday & 10 & 21 & Rain will still linger for the morning.
    Conditions will improve by early afternoon and continue
    throughout the evening. \tabularnewline[1ex]
    \bottomrule
    \end{tabular}
\end{center}


\begin{center}
    \begin{tabular}{ | l | l | l | C{5cm} |}
      \multicolumn{4}{c}{ \large \textbf{ and the bad and ugly...}} \tabularnewline[2ex]
    \hline
    Day & Min Temp & Max Temp & Summary \tabularnewline \hline
    Monday & 11C & 22C & A clear day with lots of sunshine.  
    However, the strong breeze will bring down the temperatures. \tabularnewline \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. \tabularnewline \hline
    Wednesday & 10C & 21C & Rain will still linger for the morning.
    Conditions will improve by early afternoon and continue
    throughout the evening. \tabularnewline
    \hline
    \end{tabular}
\end{center}
\end{document}

enter image description here

Related Question