2

I am currently struggling with the longtable package and horizontal lines that should visually separate rows. The thing is that I do not want to display bottom lines on the last row of each particular page and a top line on the first row of each succeeding page. My question would be if there is any variable or switch of the longtable code that i can use to determine (inside my rowend command) if this is true and then suppress the execution of hdashline? I know of the variable \LT@rows but what I have tried so far didn't give me any results.

MWE:

\documentclass[a4paper]{article}

\usepackage[english]{babel}
\usepackage[utf8x]{inputenc}
\usepackage{longtable}
\usepackage{array}
\usepackage{arydshln}

\newcommand{\rowend}{%
  \tabularnewline%
  % Determine here if it is the last row of the current page or first row of next page
  % If it is the last row of the current page, don't make a bottom dashed line.
  % If it is the first row of a succeeding page, don't make a top row (although I have no idea why that line is actually drawn ...
  \hdashline%
}

\begin{document}

\begin{longtable}{|l|r|c|p{2cm}|}
\caption{A simple longtable example}\\
\hline
\textbf{First entry} & \textbf{Second entry} & \textbf{Third entry} & \textbf{Fourth entry} \\
\hline
\endfirsthead

\multicolumn{4}{c}%
{\tablename\ \thetable\ -- \textit{Continued from previous page}} \\
\hline
\textbf{First entry} & \textbf{Second entry} & \textbf{Third entry} & \textbf{Fourth entry} \\
\hline
\endhead

\hline \multicolumn{4}{r}{\textit{Continued on next page}} \\
\endfoot
\hline
\endlastfoot

1 & 2 & 3 & 4 \rowend 1 & 2 & 3 & 4 \rowend 1 & 2 & 3 & 4 \rowend 1 & 2 & 3 & 4 \rowend
1 & 2 & 3 & 4 \rowend 1 & 2 & 3 & 4 \rowend 1 & 2 & 3 & 4 \rowend 1 & 2 & 3 & 4 \rowend
1 & 2 & 3 & 4 \rowend 1 & 2 & 3 & 4 \rowend 1 & 2 & 3 & 4 \rowend 1 & 2 & 3 & 4 \rowend
1 & 2 & 3 & 4 \rowend 1 & 2 & 3 & 4 \rowend 1 & 2 & 3 & 4 \rowend 1 & 2 & 3 & 4 \rowend
1 & 2 & 3 & 4 \rowend 1 & 2 & 3 & 4 \rowend 1 & 2 & 3 & 4 \rowend 1 & 2 & 3 & 4 \rowend
1 & 2 & 3 & 4 \rowend 1 & 2 & 3 & 4 \rowend 1 & 2 & 3 & 4 \rowend 1 & 2 & 3 & 4 \rowend
1 & 2 & 3 & 4 \rowend 1 & 2 & 3 & 4 \rowend 1 & 2 & 3 & 4 \rowend 1 & 2 & 3 & 4 \rowend
1 & 2 & 3 & 4 \rowend 1 & 2 & 3 & 4 \rowend 1 & 2 & 3 & 4 \rowend 1 & 2 & 3 & 4 \rowend
1 & 2 & 3 & 4 \rowend 1 & 2 & 3 & 4 \rowend 1 & 2 & 3 & 4 \rowend 1 & 2 & 3 & 4 \rowend
1 & 2 & 3 & 4 \rowend 1 & 2 & 3 & 4 \rowend 1 & 2 & 3 & 4 \rowend 1 & 2 & 3 & 4 \rowend
1 & 2 & 3 & 4 \rowend 1 & 2 & 3 & 4 \rowend 1 & 2 & 3 & 4 \rowend 1 & 2 & 3 & 4 \rowend
1 & 2 & 3 & 4 \rowend 1 & 2 & 3 & 4 \rowend 1 & 2 & 3 & 4 \rowend 1 & 2 & 3 & 4 \rowend

\end{longtable}

\end{document}
3

There is no such switch (and no direct way to provide one) the main idea of longtable is that it uses a standard TeX asynchronous output routine to do the page breaking. This means that, as in a normal text page, the macro layer has really no idea about what page any bit of text will finally land on.

It would be possible to use a two pass system using \pageref (or \pdfsavepos, or wrappers such as zref) to detect if one row is on a different page from the previous and so in that case omit the rule, or (perhaps) you could adjust the rule to have a special depth (say 1sp) and detect that and remove it in the output routine.

An alternative would be to use supertabular instead of longtable that does the page breaking "by hand" within the table macros measuring the height and then stopping the table forcing a break and starting a new one internally. In such a system it is much easier to "know" that you are the last row of a page.

  • David, thank you for your insightful explanation. The point with the asynchronous output routine makes totally sense to, although I'm a little bit overwhelmed by how to achieve it with pageref, as I'm dynamically creating the table as you suggested in this post tex.stackexchange.com/a/161078/46403. – hetsch Jan 4 '16 at 10:58
  • @hetsch idea would be that at the end of a row that you want to follow with an optional \hline do \label{some-generated-name-a}\\\myhline\label{some-generated-name-b} then define myhline to do an \hline unless both the labels -a and -b are defined from the previous run and \pageref shows they are on separate pages, in which case omit the hline. – David Carlisle Jan 4 '16 at 11:06
  • Thousand thanks, I'll definitely give it a try this evening! – hetsch Jan 4 '16 at 11:14

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.