[Tex/LaTex] Double header in longtable

longtablelyxrtables

I'm trying to make a longtable and use some R tools for generating them. The problem is that when a long table has more than one columns, it creates double headers, as shown here: https://stackoverflow.com/questions/20552459/excessive-elements-in-latex-longtable-output-when-more-than-one-row-is-used-in-h. I use LyX to generate the output.

This is one-column code:

\begin{document}

\setlongtables


\begin{longtable}{r}\caption{Title} \tabularnewline
\hline\hline
\multicolumn{1}{c}{X1.10}\tabularnewline
\hline
\endfirsthead\caption[]{\em (continued)} \tabularnewline
\hline
\multicolumn{1}{c}{X1.10}\tabularnewline
\hline
\endhead
\hline
\endfoot
\label{data.frame}
$ 1$\tabularnewline
$ 2$\tabularnewline
$ 3$\tabularnewline
$ 4$\tabularnewline
$ 5$\tabularnewline
$ 6$\tabularnewline
$ 7$\tabularnewline
$ 8$\tabularnewline
$ 9$\tabularnewline
$10$\tabularnewline
\hline
\end{longtable}

\end{document}

And this is a two-column table:

\begin{document}

\setlongtables


\begin{longtable}{rr}\caption{Title} \tabularnewline
\hline\hline
\multicolumn{1}{c}{X1.10}&\multicolumn{1}{c}{X10.1}\tabularnewline
\hline
\endfirsthead\caption[]{\em (continued)} \tabularnewline
\hline
\multicolumn{1}{c}{X1.10}&\multicolumn{1}{c}{X10.1}\tabularnewline
\hline
\endhead
\hline
\endfoot
\label{data.frame}
$ 1$&$10$\tabularnewline
$ 2$&$ 9$\tabularnewline
$ 3$&$ 8$\tabularnewline
$ 4$&$ 7$\tabularnewline
$ 5$&$ 6$\tabularnewline
$ 6$&$ 5$\tabularnewline
$ 7$&$ 4$\tabularnewline
$ 8$&$ 3$\tabularnewline
$ 9$&$ 2$\tabularnewline
$10$&$ 1$\tabularnewline
\hline
\end{longtable}

\end{document}

What's wrong with the latter one? Judging from the code, they are identical.

UPDATE

That was LyX: when my .tex file was imported in LyX, it created additional code (the header), so that further processing went wrong.

Best Answer

Please always post complete documents that show the problem. I had to guess to complete your fragment but I only get one heading, so presumably the problem is in the code you didn't show.

enter image description here

\documentclass{article}
\usepackage{longtable}
\begin{document}

\setlongtables


\begin{longtable}{rr}\caption{Title} \tabularnewline
\hline\hline
\multicolumn{1}{c}{X1.10}&\multicolumn{1}{c}{X10.1}\tabularnewline
\hline
\endfirsthead\caption[]{\em (continued)} \tabularnewline
\hline
\multicolumn{1}{c}{X1.10}&\multicolumn{1}{c}{X10.1}\tabularnewline
\hline
\endhead
\hline
\endfoot
\label{data.frame}
$ 1$&$10$\tabularnewline
$ 2$&$ 9$\tabularnewline
$ 3$&$ 8$\tabularnewline
$ 4$&$ 7$\tabularnewline
$ 5$&$ 6$\tabularnewline
$ 6$&$ 5$\tabularnewline
$ 7$&$ 4$\tabularnewline
$ 8$&$ 3$\tabularnewline
$ 9$&$ 2$\tabularnewline
$10$&$ 1$\tabularnewline
\hline
\end{longtable}

\end{document}