I'm trying to reimplement the David Carlisle solution given here for breaking
long tables over certain rows (breaking in \hline
commnands instead \cline
ones). This solution is complemented with the use of \\*
command (another example here), and works perfectly with longtable
and longtabu
environments.
Now, I would like do it work with the booktabs
package, which uses a different mechanism to draw lines, especially in \hline\hline
cases.
Following the procedure given by David, I rewrote the \@cmidrulea
and \@cmidruleb
commands, which, according booktabs documentation, actually draw the rules. This is a 'minimal' example:
\documentclass[oneside,a4paper]{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{lipsum}
\usepackage[left=1in,right=1in]{geometry}
\usepackage{tabu}
\usepackage{booktabs}
\usepackage{longtable}
\usepackage{multirow} % Para las tablas (varias filas)
\usepackage[table]{xcolor} % Colores. Tambien en tablas
\newcommand{\OG}{\cellcolor{orange}}
%%%% Tomado de https://tex.stackexchange.com/questions/52100/longtable-multirow-problem-with-cline-and-nopagebreak
\makeatletter
\def\@cmidrulea{%
\multispan\@cmidla&\multispan\@cmidlb
\unskip\hskip\cmrkern@l%
{\CT@arc@\leaders\hrule \@height\@thisrulewidth\hfill}%
\hskip\cmrkern@r\cr
\noalign{\nobreak\vskip-\@thisrulewidth} %% Inserted \nobreak here
}%
\def\@cmidruleb{% This remains unchanged
\multispan\@cmidlb
\unskip\hskip \cmrkern@l%
{\CT@arc@\leaders\hrule \@height\@thisrulewidth\hfill}%
\hskip\cmrkern@r\cr
% \noalign{\nobreak\vskip-\@thisrulewidth} %% With this, "almost" works...
}%
\makeatother
\begin{document}
\lipsum[1-3]
\begin{longtabu} to \textwidth {|X[3,lm]|X[1,cm]|X[1,cm]|X[1,cm]|X[1,cm]|X[1,cm]|X[1,cm]|}
\toprule
\rowfont\bfseries
Lorem ipsum dolor sit amet, consectetuer adipiscing
elit.
& Curabitur
& Nam
& Pellentesque
& Donec
& Curabitur
& Cras\\*
\midrule
\endhead
\multicolumn{7}{r}{\small \it Continued on next page} \\* \endfoot
\endlastfoot
\multicolumn{7}{c}{\OG\textbf{First group heading}}\\*
\midrule
Lorem ipsum dolor sit amet & Terra & Integer & & Mauris & Mauris & MC \\
\midrule
Pellentesque habitant morbi tristique senectus& Terra & Integer &
& Orci & Mauris & DB \\
\midrule
Pellentesque habitant morbi tristique senectus& Terra & Integer &
& Orci & Mauris & DB \\
\midrule
Pellentesque habitant morbi tristique senectus& Terra & Integer &
& Orci & Mauris & DB \\
\midrule
\multirow{2}{\linewidth}{Pellentesque habitant morbi tristique
senectus} &
Phasellus (vehicula augue eu neque) & Integer & \textbf{
\parbox{\linewidth}{
Curabitur\\
Phasellus
}
} & Mauris & \textbf{Magna} & DB \\*
\cmidrule{2-7}
& Donec (vehicula augue eu neque) & Puella &
\textbf{Curabitur Phasellus Magna} & Mauris & \textbf{Magna} & DB \\
\midrule
\multirow{2}{\linewidth}{Pellentesque habitant morbi tristique
senectus} &
Phasellus (vehicula augue eu neque) & Integer & \textbf{
\parbox{\linewidth}{
Curabitur\\
Phasellus
}
} & Mauris & \textbf{Magna} & DB \\*
\cmidrule{2-7}
& Donec (vehicula augue eu neque) & Puella &
\textbf{Curabitur Phasellus Magna} & Mauris & \textbf{Magna} & DB \\
\midrule
\multirow{2}{\linewidth}{Pellentesque habitant morbi tristique
senectus} &
Phasellus (vehicula augue eu neque) & Integer & \textbf{
\parbox{\linewidth}{
Curabitur\\
Phasellus
}
} & Mauris & \textbf{Magna} & DB \\*
\cmidrule{2-7}
& Donec (vehicula augue eu neque) & Puella &
\textbf{Curabitur Phasellus Magna} & Mauris & \textbf{Magna} & DB \\
\midrule
\multicolumn{7}{c}{\OG\textbf{Second group heading}}\\*
\midrule
Lorem ipsum dolor sit amet & Terra & Integer & & Mauris & Mauris & MC \\
\midrule
Pellentesque habitant morbi tristique senectus& Terra & Integer &
& Orci & Mauris & DB \\
\midrule
\multirow{2}{\linewidth}{Pellentesque habitant morbi tristique
senectus} &
Phasellus (vehicula augue eu neque) & Integer & \textbf{
\parbox{\linewidth}{
Curabitur\\
Phasellus
}
} & Mauris & \textbf{Magna} & DB \\*
\cmidrule{2-7}
& Donec (vehicula augue eu neque) & Puella &
\textbf{Curabitur Phasellus Magna} & Mauris & \textbf{Magna} & DB \\
\midrule
\multirow{2}{\linewidth}{Pellentesque habitant morbi tristique
senectus} &
Phasellus (vehicula augue eu neque) & Integer & \textbf{
\parbox{\linewidth}{
Curabitur\\
Phasellus
}
} & Mauris & \textbf{Magna} & DB \\*
\cmidrule{2-7}
& Donec (vehicula augue eu neque) & Puella &
\textbf{Curabitur Phasellus Magna} & Mauris & \textbf{Magna} & DB \\
\midrule
\multicolumn{7}{c}{\OG\textbf{Third group heading}}\\*
\midrule
%\cmidrule{1-7} %% Ouch!
\multirow{2}{\linewidth}{Pellentesque habitant morbi tristique
senectus} &
Phasellus (vehicula augue eu neque) & Integer & \textbf{
\parbox{\linewidth}{
Curabitur\\
Phasellus
}
} & Mauris & \textbf{Magna} & DB \\*
\cmidrule{2-7}
& Donec (vehicula augue eu neque) & Puella &
\textbf{Curabitur Phasellus Magna} & Mauris & \textbf{Magna} & DB \\
\bottomrule
\caption{Fiat iustitia, ne pereat mundus.}
\label{tab:fiat-iustitia}
\tabuphantomline
\end{longtabu}
\end{document}
As you can see if you process the document, there is a page breaking in the third heading group, even with a explicit no break \\*
command.
As desperate solution, I've tried replace the \midrule
command by a less elegant \cmidrule{1-7}
but this only almost work if I uncomment the \nobreak
line in \@cmidruleb
(re)definition. If I do this, the page breaks correctly, but last line is drawn in the next page. I'm also interested in this last case because I'll probably need it with multirow cells in the right side of the table, with \cmidrule{1-n}
commands.
Can anyone help me?
Thanks in advance.