1

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{%
\multispan\LT@cols\unskip\leaders\hrule\@height\arrayrulewidth\hfill\cr
\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`

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

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{%
\multispan\LT@cols\unskip\leaders\hrule\@height\arrayrulewidth\hfill\cr
\noalign{\penalty10000\vskip\doublerulesp}%
\multispan\LT@cols\unskip\leaders\hrule\@height\arrayrulewidth\hfill\cr
\noalign{\penalty10000}%
}
0

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

enter image description here

\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
        \multicolumn{4}{|l|}{Popis} & M J & AD & AD & CD\\
    \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}
1
  • 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
0

Workaround with the help from David Carlisle:

\documentclass{article}
\usepackage{longtable}

\makeatletter
\def\nobreakhline{%
\multispan\LT@cols\unskip\leaders\hrule\@height\arrayrulewidth\hfill\cr
    \noalign{\penalty10000}}
\makeatother

\makeatletter
\def\nobreakhlinedouble{%
    \multispan\LT@cols\unskip\leaders\hrule\@height\arrayrulewidth\hfill\cr
    \noalign{\penalty10000\vskip\doublerulesep}
    \multispan\LT@cols\unskip\leaders\hrule\@height\arrayrulewidth\hfill\cr
    \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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.