# Longtable behaviour of adapted \hline (\nobreakhline)

I work with longtables and a workaround with \nobreakhline. Somehow the workaround does not really work as the real \hline if two lines should be put after each other. So I want the same apperance as in the first table with \hline\hline but make use of \nobreakhline.

\documentclass{article}
\usepackage{longtable}

\makeatletter
\def\nobreakhline{%
\noalign{\penalty10000}}
\makeatother

\begin{document}

\begin{longtable}{p{2cm}|p{3cm}|p{3cm}}
\caption{Blabla} \\
\hline\hline
8,8 &85,3 &1,4 \\\hline
8,8 &85,3 &1,4 \\\hline
\hline
\end{longtable}

\begin{longtable}{p{2cm}|p{3cm}|p{3cm}}
\caption{Blabla} \\
\nobreakhline\nobreakhline
8,8 &85,3 &1,4 \\*\nobreakhline
8,8 &85,3 &1,4 \\*\nobreakhline
\nobreakhline
\end{longtable}

\end{document}


How can this be achieved? Space between \hline\hline in longtable

• did the answer meet your requirement -- please let us know – js bibra Feb 18 '20 at 0:54

Looking ahead to make \hline\hline is by far the most complicated part of hline, it could be copied to nobreakhline but if you wanted to support things like \hline\nobreakhline it gets even worse so I would simply define a second command that makes the double rule, say

\def\nobreakhhline{%
\noalign{\penalty10000\vskip\doublerulesp}%
\noalign{\penalty10000}%
}


Is this what you are looking for -- the solution has been given by @DavidCarlisle -- https://tex.stackexchange.com/a/107566/197451

\documentclass{article}
\usepackage{color}

\makeatletter
\let\xx@begindocumenthook\@begindocumenthook
\let\xxhline\hline
\let\xx@xhline\@xhline

\usepackage{colortbl}
\let\hline\xxhline
\let\@xhline\xx@xhline
\let\@begindocumenthook\xx@begindocumenthook
\makeatother

\usepackage{longtable}

\begin{document}
\begin{longtable}{|l|l|l|l|c|r|r|r|}
\caption{{ABD}}
\label{tab:SO}\\
\hline
\multicolumn{1}{|l|}{{SO} - 01} & \multicolumn{7}{ c| }{AD}\\
\hline\hline
\hline
\multicolumn{4}{|l|}{AD }& $3$ & 37000 & 0,32& 11\,800   \\
\hline
\end{longtable}
\begin{longtable}{p{2cm}|p{3cm}|p{3cm}}
\caption{Blabla} \\
\hline\hline
8,8 &85,3 &1,4 \\\hline
8,8 &85,3 &1,4 \\\hline
\hline
\end{longtable}
\begin{longtable}{p{2cm}|p{3cm}|p{3cm}}
\caption{Blabla} \\
\hline\hline
8,8 &85,3 &1,4 \\*\hline
8,8 &85,3 &1,4 \\*\hline
\hline
\end{longtable}
\end{document}

• Thank you. I do not have a deep understanding of the code inside \makeatletter... However this solution is not able to control the pagebreak via \nobreakhline. Even in Table 3 you only use \\* so in case of using \hline a pagebreak is allowed. I want to use both of them (\\* and \nobreakhline together or \\ and \hline together) at certain positions to allow and completely disallow pagebreaks within the longtable rows. – konsens Mar 10 '20 at 9:26

Workaround with the help from David Carlisle:

\documentclass{article}
\usepackage{longtable}

\makeatletter
\def\nobreakhline{%
\noalign{\penalty10000}}
\makeatother

\makeatletter
\def\nobreakhlinedouble{%
\noalign{\penalty10000\vskip\doublerulesep}
\noalign{\penalty10000}}
\makeatother

\begin{document}

\begin{longtable}{p{2cm}|p{3cm}|p{3cm}}
\caption{Blabla} \\
\hline\hline
8,8 &85,3 &1,4 \\\hline
8,8 &85,3 &1,4 \\\hline
\hline
\end{longtable}

\begin{longtable}{p{2cm}|p{3cm}|p{3cm}}
\caption{Blabla} \\
\nobreakhlinedouble
8,8 &85,3 &1,4 \\*\nobreakhline
8,8 &85,3 &1,4 \\*\nobreakhline
\nobreakhlinedouble
\end{longtable}

\end{document}


At the end it makes a double line in one and then another line. This is better for coding the row input.