1

I am attempting to use longtables since my table will span several pages. The problem I have now is that the captions are floating over top of the table making it difficult to read the table. I want the caption below the table for each page it is on, but am not sure how to accomplish that.

\usepackage{longtable}
\section{System}
\begin{longtable}[H]
\begin{center}
\rowcolors{2}{gray!15}{white}
\begin{tabular}{|p{0.20\linewidth}|p{0.80\linewidth}|}
\hline
\rowcolor{cyan}
\textbf{field} & \textbf{value}
\\ \hline
website & http://www.funtoo.org \\ \hline
\end{tabular}
\end{center}
\caption{Funtoo Details}
\label{Funtoo Details}
\end{longtable}
  • Obviously, this is not the table that has too many rows in it, but just serves as an example of the problem. – Walter Jul 15 '16 at 3:17
  • 2
    Please make your code snippet compilable! Inside longtable you do not need tabular, please check the documentation with texdoc longtable ... Welcome to TeX.SE! – Mensch Jul 15 '16 at 3:45
3

Do take some time to master the structure (and syntax) of longtable environments:

  • Don't use tabular environments inside a longtable environment. Really: don't do it.
  • Don't use center environments inside a longtable environment -- it's automatically centered (assuming it's not wider than \linewidth by design or accident...)
  • The full width of your tabular is not \linewidth but \linewidth + 4\tabcolsep + 3\arrayrulewidth. That's not the intention, is it?
  • A longtable doesn't float -- the [H] positioning specifier doesn't do anything at all (other than clutter up the code)

The following may be a useful starting point for further refinements. Note how (a) I've separated out the header, the footer, and the body of the longtable and (b) provided calculations for the usable widths of the two columns.

\documentclass{article}
\usepackage{longtable,url}
\begin{document}
\section{System}

\begin{longtable}{|p{\dimexpr0.2\linewidth-2\tabcolsep-1.5\arrayrulewidth\relax}|
                   p{\dimexpr0.8\linewidth-2\tabcolsep-1.5\arrayrulewidth\relax}|}
%% define the header 
\hline
%\rowcolor{cyan}
\textbf{field} & \textbf{value}\\ 
\hline
\endhead
%% define the footer
\hline
\multicolumn{1}{c}{}\\ % blank line
\caption{Funtoo Details}
\label{Funtoo Details}
\endfoot
%% body of table
website & \url{http://www.funtoo.org} \\ 
website & \url{http://www.funtoo.org} \\ 
website & \url{http://www.funtoo.org} \\ 
website & \url{http://www.funtoo.org} \\ 
website & \url{http://www.funtoo.org} \\ 
\end{longtable}
\end{document}
  • Thanks, that worked. I had all of those things because I converted directly from my table usage. Now, I'd like to re-add the colors I had, but that is a minor detail. – Walter Jul 15 '16 at 10:37
  • I re-added the colors, so that worked perfectly for me. – Walter Jul 16 '16 at 2:02

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.