I use tabu
package to easily typeset tables. Now i need to typeset long table. So i used longtabu
. The head of the table consists of much columns. Also there are lots of text in each cell and some cells should be spanned. As i think, the centered text (formatted as paragraph) would look better.
Minimal example
\documentclass[14pt,twoside]{extreport}
\usepackage{type1ec}
\usepackage[T2A]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
\usepackage{multirow}
\usepackage{array}
\usepackage{longtable}
\usepackage{tabu}
\usepackage{xparse}
\usepackage[unicode=true]{hyperref}
\NewDocumentCommand{\rot}{O{90} O{1em} m}{\makebox[#2][l]{\rotatebox{#1}{#3}}}%
\begin{document}
\newlength{\firsttoprow}
\setlength{\firsttoprow}{3cm}
\begin{longtabu} to \linewidth%
{|X[25,C]%
|X[15,C]|X[15,C]|X[15,C]%
|X[25,C]%
|X[25,C]|}
\caption{First table caption%
\label{tab:first}}\\\hline
\multirow{2}*{\parbox{\linewidth}{\centering Column A (first page head)}}%
& \rot{\parbox{\firsttoprow}{\centering Column B}}%
& \rot[90][5ex]{\parbox{\firsttoprow}{\centering Column C (two lines)}}%
& \rot[90][5ex]{\parbox{\firsttoprow}{\centering Column D (two lines)}}%
& \multirow{2}*{\rot[90][7.5ex]{\parbox{\firsttoprow}{\centering Column E (consists of three lines)}}}%
& \multirow{2}*{\rot[90][5ex]{\parbox{\firsttoprow}{\centering Column F (two lines)}}}\\\cline{2-4}
& B (two lines)%
& C (three lines)%
& D & &\\\hline
\endfirsthead
\caption*{Table \ref{tab:first} (Cont.)}\\\hline
Column A (head)%
& B & C & D%
& Col. E%
& Col. F\\\hline
\endhead
Cont A%
& Cnt.B & Cnt.C & Cnt.D%
& Cnt.E%
& Cnt.F\\\hline
\end{longtabu}
\end{document}
The rotation is made with xparse
(see https://tex.stackexchange.com/a/32687/33087). There are problems:
- At the top row in columns B, C and D bottom vertical space between box and horizontal line is bigger. I want content to be at the middle of cell.
- Content of spanned head cells (columns A, E and F) vertically alligned by
\multirow
so the centers of boxes are located at the line between rows of head. I want the centers of boxes are located at centers of spanned cells. - This example produces 6 bad boxes (overfull
\vbox
due to\multirow
).
The second example provides ugly workaround with manual vertical fixups and without \multirow
:
\documentclass[14pt,twoside]{extreport}
\usepackage{type1ec}
\usepackage[T2A]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
\usepackage{multirow}
\usepackage{array}
\usepackage{longtable}
\usepackage{tabu}
\usepackage{xparse}
\usepackage[unicode=true]{hyperref}
\newcolumntype{Y}[1]{>{\strut\hspace{0pt}}X[#1]<{\hspace{0pt}\strut}}
\tabucolumn Y
\NewDocumentCommand{\rot}{O{90} O{1em} m}{\makebox[#2][l]{\rotatebox{#1}{#3}}}%
\begin{document}
\newlength{\firsttoprow}
\newlength{\fixuptoprow}
\setlength{\firsttoprow}{3cm}
\setlength{\fixuptoprow}{2cm}
\begin{longtabu} to \linewidth%
{|Y{25,C}%
|Y{15,C}|Y{15,C}|Y{15,C}%
|Y{25,C}%
|Y{25,C}|}
\caption{First table caption%
\label{tab:first}}\\\hline
\begin{minipage}[t][0pt]{\linewidth}\vspace{-\fixuptoprow}\vspace{3.5ex}%
\parbox{\linewidth}{\centering Column A (first page head)}%
\end{minipage}%
& \rot{\parbox{\firsttoprow}{\centering Column B}}%
& \rot[90][5ex]{\parbox{\firsttoprow}{\centering Column C (two lines)}\hspace{1ex}}%
& \rot[90][5ex]{\parbox{\firsttoprow}{\centering Column D (two lines)}}%
& \begin{minipage}[t][0pt]{7.5ex}\vspace{-\fixuptoprow}%
\rot[90][7.5ex]{\parbox{\firsttoprow}{\centering Column E (consists of three lines)}}%
\end{minipage}%
& \begin{minipage}[t][0pt]{5ex}\vspace{-\fixuptoprow}%
\rot[90][5ex]{\parbox{\firsttoprow}{\centering Column F (two lines)}}%
\end{minipage}\\\cline{2-4}
& B (two lines)%
& C (three lines)%
& D & &\\\hline
\endfirsthead
\caption*{Table \ref{tab:first} (Cont.)}\\\hline
Column A (head)%
& B & C & D%
& Col. E%
& Col. F\\\hline
\endhead
Cont A%
& Cnt.B & Cnt.C & Cnt.D%
& Cnt.E%
& Cnt.F\\\hline
\end{longtabu}
\end{document}
I hope someone can suggest beautiful decision which calculates fixups automatically. Also, for minipage
decision see https://tex.stackexchange.com/a/99684/33087.
Best Answer
I'd use a much simpler markup, and do away with the vertical rules.