Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.
  1. I want to fit this table on a portrait format page
  2. and make the columns that show numbers to be of equal width

    however, type 3 has a longer name than the others, hence

  3. setting the column heads diagonally might help me fit the longer name in
    so that condition 1. can be fulfilled

this example does not work and I seem to need some advice on how to combine \rotatebox with \multicolumn

or maybe you have a different idea altogether how I can solve this with conditions 1. and 2.

\documentclass[a4paper,10pt]{scrartcl} \usepackage[latin1]{inputenc} \usepackage{babel} \usepackage[T1]{fontenc} \usepackage{booktabs} \usepackage{array} \usepackage{dcolumn} \usepackage{graphicx}  
\begin{document}  
\begin{table}  
\centering  
\caption{Caption text}  
\begin{tabular}{ | l | p{0.45cm} | p{0.45cm} | p{0.45cm} | p{0.45cm} | p{0.45cm} | p{0.45cm} | p{0.45cm} | p{0.45cm} | p{0.45cm} | p{0.45cm} | p{0.45cm} | p{0.45cm} |}  
\hline  
 & \multicolumn{2}{*}{\rotatebox{60}{Type 1}} & \multicolumn{2}{*}{\rotatebox{60}{Type 2}} & \multicolumn{2}{*}{\rotatebox{60}{Type 3 longer text}} & \multicolumn{2}{*}{\rotatebox{60}{Type 4}} & \multicolumn{2}{*}{\rotatebox{60}{Type 5}} & \multicolumn{2}{*}{\rotatebox{60}{Type 6}}\\\hline  
\multicolumn{13}{|l|}{\textsc{\textbf{row title bold}}} \\ \hline  
Criterium 1 & 5 & 10 & 3 & 6 & 1 & 2 & 5 & 10 & 5 & 10 & 5 & 10 \\ \hline  
Criterium 2 & 4 & 8 & 3 & 6 & 2 & 4 & 3 & 6 & 4 & 8 & 4 & 8 \\ \hline  
\multicolumn{13}{|l|}{\textsc{\textbf{row title bold}}} \\ \hline  
Criterium 3 & 5 & 5 & 5 & 5 & 4 & 4 & 5 & 5 & 5 & 5 & 5 & 5 \\ \hline  
Criterium 4 & 5 & 5 & 1 & 1 & 1 & 1 & 1 & 1 & 1 & 1 & 1 & 1 \\ \hline  
\textbf{\textsc {Sum}} &  & \textbf{84} & & \textbf{56} & & \textbf{50}& &  \textbf{53}& & \textbf{51}& & \textbf{51} \\ \hline  
\end{tabular}  
\label{tab:Label text}  
\end{table}  
\end{document}  
share|improve this question
    
You wrongly use \multicolumn. You can use \multicolumn{2}{c}{\rotatebox{60}{Type 1}}, but never use *. –  Leo Liu Mar 26 '11 at 11:57
add comment

2 Answers

Just use tabularx. I didn't change much of the contents of the table.

\documentclass{article}
\usepackage{tabularx}
\newcolumntype{R}{>{\raggedleft\arraybackslash}X}
\begin{document}
\begin{table}
\newcommand\MC[1]{\multicolumn{2}{X|}{#1}}
\centering
\caption{Caption text}
\begin{tabularx}{\textwidth}{|l|*{12}{R|}}
\hline
 & \MC{Type~1} & \MC{Type~2} & \MC{Type~3 longer text}
 & \MC{Type~4} & \MC{Type~5} & \MC{Type~6}\\\hline
\multicolumn{13}{|l|}{\textsc{\textbf{row title bold}}} \\ \hline
Criterium 1 & 5 & 10 & 3 & 6 & 1 & 2 & 5 & 10 & 5 & 10 & 5 & 10 \\ \hline
Criterium 2 & 4 & 8 & 3 & 6 & 2 & 4 & 3 & 6 & 4 & 8 & 4 & 8 \\ \hline
\multicolumn{13}{|l|}{\textsc{\textbf{row title bold}}} \\ \hline
Criterium 3 & 5 & 5 & 5 & 5 & 4 & 4 & 5 & 5 & 5 & 5 & 5 & 5 \\ \hline
Criterium 4 & 5 & 5 & 1 & 1 & 1 & 1 & 1 & 1 & 1 & 1 & 1 & 1 \\ \hline
\textbf{\textsc{Sum}}
 && \textbf{84} && \textbf{56} && \textbf{50}
 && \textbf{53} && \textbf{51} && \textbf{51} \\ \hline
\end{tabularx}
\label{tab:Label text}
\end{table}
\end{document}

enter image description here

share|improve this answer
add comment

For what it's worth, you can place the heading elements in a \makebox[<len>][<align>]{<stuff>} that will typeset <stuff> in a box of width <len>, even if <stuff> is wider/thinner than <len>. The alignment specification <align> is similar to that of the array or tabular column specification.

The following MWE provides \rothead[<angle>]{<stuff>} (as a redefinition from the makecell package) that rotates <stuff> by angle <angle> (default is 60 degrees with this argument being optional). It also places <stuff> in a box of fixed 9mm width, centered c. Additionally you can use \\ to make a newline within <stuff>.

enter image description here

\documentclass[a4paper,10pt]{scrartcl}
\usepackage[T1]{fontenc}% http://ctan.org/pkg/fontenc
\usepackage{graphicx}% http://ctan.org/pkg/graphicx
\usepackage{makecell}% http://ctan.org/pkg/makecell
\renewcommand{\rothead}[2][60]{\makebox[9mm][c]{\rotatebox{#1}{\makecell[c]{#2}}}}%
\begin{document}
\begin{table}  
  \centering  
  \caption{Caption text}  
  \begin{tabular}{|l|*{12}{p{0.45cm}|}}
    \multicolumn{1}{c}{} & \multicolumn{2}{c}{\rothead{Type 1}} & \multicolumn{2}{c}{\rothead{Type 2}} 
      & \multicolumn{2}{c}{\rothead{Type 3 longer text\\than other headings}} & \multicolumn{2}{c}{\rothead{Type 4}}
      & \multicolumn{2}{c}{\rothead{Type 5}} & \multicolumn{2}{c}{\rothead{Type 6}} \\
    \hline
    \multicolumn{13}{|l|}{\textsc{\textbf{row title bold}}} \\ \hline
    Criterion 1 & 5 & 10 & 3 & 6 & 1 & 2 & 5 & 10 & 5 & 10 & 5 & 10 \\ \hline  
    Criterion 2 & 4 & 8 & 3 & 6 & 2 & 4 & 3 & 6 & 4 & 8 & 4 & 8 \\ \hline  
    \multicolumn{13}{|l|}{\textsc{\textbf{row title bold}}} \\ \hline  
    Criterion 3 & 5 & 5 & 5 & 5 & 4 & 4 & 5 & 5 & 5 & 5 & 5 & 5 \\ \hline  
    Criterion 4 & 5 & 5 & 1 & 1 & 1 & 1 & 1 & 1 & 1 & 1 & 1 & 1 \\ \hline  

    \textbf{\textsc{Sum}} & & \textbf{84} & & \textbf{56} & & \textbf{50} & & \textbf{53} 
      & & \textbf{51} & & \textbf{51} \\ \hline  
  \end{tabular}  
  \label{tab:Label text}  
\end{table}  
\end{document}

If you're interested in seeing the size of the boxes that the rotated headings are contained, use the following redefinition of \rothead instead:

\renewcommand{\rothead}[2][60]{\framebox[9mm][c]{\rotatebox{#1}{\makecell[c]{#2}}}}%

enter image description here

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.