[Tex/LaTex] How to wrap the 90 degrees rotated text in a table cell

line-breakingrotatingtables

in Microsoft word I have a table which has the following structure.

enter image description here

Now, I need to make a similar table in LaTex to submit a publication, I tried with the following code,

%%***************************************************************
\documentclass[twoside,12pt]{article}%                         *
\usepackage{graphicx}%                                           *

\begin{document}
%===============Table Starts====================================
Table 1. This is a table 
\begin{center}%[htbp]
\begin{tabular}{l rrrrrrrr}\hline
\rotatebox{90}{Number of 
Married Years}  & \rotatebox{90}{Observed Frequency (Year 1)}   & \rotatebox{90}{Expected Poisson Frequency (Year 1)} & 
\rotatebox{90}{Expected Binomal Frequency (Year 1)} & \rotatebox{90}{Expected Normal Frequency (Year 1)}    & \rotatebox{90}{Observed Frequency (Year 2)} & \rotatebox{90}{Expected Poisson Frequency (Year 2)} & \rotatebox{90}{   Expected Binomial
Frequency (Year 2) } & \rotatebox{90}{Expected Normal Frequency (Year 2)}\\\hline
            0     & x     & y     & z     & a     & b     & c     & d     & e \\
            1     & x     & y     & z     & a     & b     & c     & d     & e \\
            2     & x     & y     & z     & a     & b     & c     & d     & e \\
            3     & x     & y     & z     & a     & b     & c     & d     & e \\\hline
\end{tabular}
\label{tab1}
\end{center} 
\end{document}

This code produces a table like the below,

enter image description here

It would be a great help if you could guide me in wrapping the rotated text in the first row of the table.

Best Answer

\parbox is an obvious choice here. I've wrapped this in a command \spheading[<width>]{<stuff>} (default of width is 10em), to avoid duplication of angles:

enter image description here

\documentclass{article}
\usepackage{graphicx}% http://ctan.org/pkg/graphicx
\newcommand{\spheading}[2][10em]{% \spheading[<width>]{<stuff>}
  \rotatebox{90}{\parbox{#1}{\raggedright #2}}}
\begin{document}
%===============Table Starts====================================
Table 1. This is a table 
\begin{center}%[htbp]
  \begin{tabular}{l *{8}{r}}
    \hline
    \spheading{Number of Married Years} & 
    \spheading{Observed Frequency (Year 1)} & 
    \spheading{Expected Poisson Frequency (Year 1)} & 
    \spheading{Expected Binomal Frequency (Year 1)} & 
    \spheading{Expected Normal Frequency (Year 1)} & 
    \spheading{Observed Frequency (Year 2)} & 
    \spheading{Expected Poisson Frequency (Year 2)} & 
    \spheading{Expected Binomial Frequency (Year 2)} & 
    \spheading{Expected Normal Frequency (Year 2)} \\
    \hline
    0     & x     & y     & z     & a     & b     & c     & d     & e \\
    1     & x     & y     & z     & a     & b     & c     & d     & e \\
    2     & x     & y     & z     & a     & b     & c     & d     & e \\
    3     & x     & y     & z     & a     & b     & c     & d     & e \\
    \hline
  \end{tabular}
\end{center} 
\end{document}

Without more information, I've kept the column alignment as-is. However, a centred display would look better here.