# Longtable: Variable or switch to determine if row is the first or last one of the current page

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

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

\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}


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.
• @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