16

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.

1

1 Answer 1

14

\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.

7
  • Very simple answer @Werner.... how can we have it in the center? :)
    – karathan
    Feb 5, 2013 at 17:30
  • 2
    @karathan - To center-set the columns, you could replace *{8}{r} with *{8}{c} in the argument of the tabular environment.
    – Mico
    Feb 5, 2013 at 17:33
  • Really with LaTeX sometimes laugh at myself ... the solution is in my legs and I look at the stars.:) I tried to do it with, \centering and the result was something else, thanks @Mico
    – karathan
    Feb 5, 2013 at 17:39
  • 1
    The ascenders of the b and d nearly touch the rule, so I think you might want a little more space between the rule and the entries. Feb 5, 2013 at 17:42
  • 1
    @Amir: You would use \spheading[15em]{<stuff>} (or some other length) instead of just \spheading{<stuff>}, which defaults to a \parbox of width 10em.
    – Werner
    Mar 2, 2016 at 19:33

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .