5

I am writing a long table with several complex things inside. When I realized I needed a multiple page table I tried to change table to longtable, but it just gives me a lot of errors.

How can I achieve to get a multiple page table?

code with normal table:

\documentclass[12pt,a4paper,final]{report}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}

\usepackage{booktabs}
\usepackage[table]{xcolor}

\usepackage{listings}
\colorlet{listingscolor}{black!15}
\lstnewenvironment{mylistings}
  {\lstset{language=C++,
    backgroundcolor=\color{listingscolor}, % set backgroundcolor
    basicstyle=\footnotesize,% basic font setting
    }%
  }
  {}

\lstnewenvironment{cpptable}
  {\lstset{language=C++,
    basicstyle=\footnotesize,% basic font setting
    }%
  }
  {}


\begin{document}


\begin{table}[H]
\caption{C++ DIC class public functions.}
\centering
\begin{tabular}{>{\columncolor{listingscolor}}l c c c}
\toprule[0.2em]

\multicolumn{1}{c}{\textbf{Function in C++} }& \textbf{Input} & \textbf{Output} & \shortstack{\textbf{Document} \\ \textbf{corresponding chapter} }\\
\hline
\midrule
\multicolumn{4}{c}{Main setup and API functions. Public functions.}\\
\hline
\begin{cpptable}
 getF() 
\end{cpptable}
 &
   \begin{minipage}{1.5in}
    \vspace{4pt}
    \begin{itemize}
   \item Subset center
   \vspace{-10pt}
   \item window size
   \end{itemize}
   \end{minipage}
   \vspace{4pt}
  &   
   \begin{minipage}{1.5in}
    \vspace{4pt}
    \begin{itemize}
   \item Undeformed \\image subset
   \end{itemize}
   \end{minipage}
   \vspace{4pt}

    & \ref{sec:basic principles},\ref{sec:sub-pixel}\\
  \hline


  \bottomrule
\end{tabular}

\label{tab:DIC class private}
\end{table}
\end{document}

What I have tried:

\documentclass[12pt,a4paper,final]{report}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}

\usepackage{booktabs}
\usepackage[table]{xcolor}

\usepackage{listings}
\colorlet{listingscolor}{black!15}
\lstnewenvironment{mylistings}
  {\lstset{language=C++,
    backgroundcolor=\color{listingscolor}, % set backgroundcolor
    basicstyle=\footnotesize,% basic font setting
    }%
  }
  {}

\lstnewenvironment{cpptable}
  {\lstset{language=C++,
    basicstyle=\footnotesize,% basic font setting
    }%
  }
  {}


\begin{document}


\begin{longtable}[H]
\caption{C++ DIC class public functions.}
\centering
\begin{tabular}{>{\columncolor{listingscolor}}l c c c}
\toprule[0.2em]

\multicolumn{1}{c}{\textbf{Function in C++} }& \textbf{Input} & \textbf{Output} & \shortstack{\textbf{Document} \\ \textbf{corresponding chapter} }\\
\hline
\midrule
\multicolumn{4}{c}{Main setup and API functions. Public functions.}\\
\hline
\begin{cpptable}
 getF() 
\end{cpptable}
 &
   \begin{minipage}{1.5in}
    \vspace{4pt}
    \begin{itemize}
   \item Subset center
   \vspace{-10pt}
   \item window size
   \end{itemize}
   \end{minipage}
   \vspace{4pt}
  &   
   \begin{minipage}{1.5in}
    \vspace{4pt}
    \begin{itemize}
   \item Undeformed \\image subset
   \end{itemize}
   \end{minipage}
   \vspace{4pt}

    & \ref{sec:basic principles},\ref{sec:sub-pixel}\\
  \hline


  \bottomrule
\end{tabular}

\label{tab:DIC class private}
\end{longtable}
\end{document}
6
  • A longtable environment shouldn't be used inside a table environment.
    – egreg
    Jun 17 '13 at 14:52
  • @egreg I actually tried to replace table by longtable, as in a example I found in the web Jun 17 '13 at 14:53
  • Please replace table and tabular with longtable in the way you tried. It will be easier to help you in finding what's wrong.
    – egreg
    Jun 17 '13 at 14:56
  • @DavidCarlisle ? Is there something wrong with my question?? Jun 17 '13 at 15:02
  • 2
    @AnderBiguri Don't worry! David is rightly proud of his own creature.
    – egreg
    Jun 17 '13 at 15:11
5

Something more like this (although it is still too wide for the page)

enter image description here

\documentclass[12pt,a4paper,final]{report}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}

\usepackage{longtable,booktabs}
\usepackage[table]{xcolor}

\usepackage{listings}
\colorlet{listingscolor}{black!15}
\lstnewenvironment{mylistings}
  {\lstset{language=C++,
    backgroundcolor=\color{listingscolor}, % set backgroundcolor
    basicstyle=\footnotesize,% basic font setting
    }%
  }
  {}

\lstnewenvironment{cpptable}
  {\lstset{language=C++,
    basicstyle=\footnotesize,% basic font setting
    }%
  }
  {}


\begin{document}

\small
\begin{longtable}{>{\columncolor{listingscolor}}l c c c}
\caption{C++ DIC class public functions.\label{tab:DIC class private}}\\

\toprule[0.2em]

\multicolumn{1}{c}{\textbf{Function in C++} }& \textbf{Input} & \textbf{Output} & \textbf{\begin{tabular}{@{}c@{}}
Document \\corresponding\\ chapter\end{tabular}}\\
\hline
\midrule
\multicolumn{4}{c}{Main setup and API functions. Public functions.}\\
\hline
\begin{cpptable}
 getF() 
\end{cpptable}
 &
   \begin{minipage}{1.5in}
    \vspace{4pt}
    \begin{itemize}
   \item Subset center
   \vspace{-10pt}
   \item window size
   \end{itemize}
   \end{minipage}
   \vspace{4pt}
  &   
   \begin{minipage}{1.5in}
    \vspace{4pt}
    \begin{itemize}
   \item Undeformed \\image subset
   \end{itemize}
   \end{minipage}
   \vspace{4pt}

    & \ref{sec:basic principles},\ref{sec:sub-pixel}\\
  \hline


  \bottomrule



\end{longtable}
\end{document}
12
  • The problem with the width is something appart, ill try to solve it later. Thank you for the answer Jun 17 '13 at 15:24
  • Damn I didnt know the package was yours, thats why you where surprised! haha Jun 17 '13 at 15:30
  • @AnderBiguri :-) Jun 17 '13 at 15:31
  • 1
    @AnderBiguri It is part of the required core latex distribution, either it is there or whoever gave you latex broke the latex licence conditions. Jun 17 '13 at 15:41
  • 1
    @AnderBiguri I only mentioned that as you would not expect to see longtable in an optional package in the package manager as it is a required part of latex. Sorry I can't help with the miktex configuration I have not used it. Jun 17 '13 at 16:09
6

A longtable environment makes the table, so it shouldn't have a tabular inside it. Here's how you can do; check with the package manual for other adjustments.

\documentclass[12pt,a4paper,final]{report}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}

\usepackage[margin=1cm]{geometry}
\usepackage{booktabs,longtable}
\usepackage[table]{xcolor}

\usepackage{listings}
\colorlet{listingscolor}{black!15}
\lstnewenvironment{mylistings}
  {\lstset{language=C++,
    backgroundcolor=\color{listingscolor}, % set backgroundcolor
    basicstyle=\footnotesize,% basic font setting
    }%
  }
  {}

\lstnewenvironment{cpptable}
  {\lstset{language=C++,
    basicstyle=\footnotesize,% basic font setting
    }%
  }
  {}


\begin{document}


\begin{longtable}{>{\columncolor{listingscolor}}l c c c}
% Here starts the first header
\caption{C++ DIC class public functions.}\label{tab:DIC class private}\\
\toprule
\multicolumn{1}{c}{\textbf{Function in C++} }&
  \textbf{Input} &
  \textbf{Output} &
  \begin{tabular}{@{}c@{}}\textbf{Document} \\ \textbf{corresponding chapter}\end{tabular}\\
\midrule
\multicolumn{4}{c}{Main setup and API functions. Public functions.}\\
\midrule
\endfirsthead

% Here starts the header specification for the following pages
\toprule
\multicolumn{1}{c}{\textbf{Function in C++} }&
  \textbf{Input} &
  \textbf{Output} &
  \begin{tabular}{@{}c@{}}\textbf{Document} \\ \textbf{corresponding chapter}\end{tabular}\\
\midrule
\multicolumn{4}{c}{Main setup and API functions. Public functions.}\\
\midrule
\endhead

% now the table contents

\begin{cpptable}
 getF() 
\end{cpptable}
 &
   \begin{minipage}{1.5in}
    \vspace{4pt}
    \begin{itemize}
   \item Subset center
   \vspace{-10pt}
   \item window size
   \end{itemize}
   \end{minipage}
   \vspace{4pt}
  &   
   \begin{minipage}{1.5in}
    \vspace{4pt}
    \begin{itemize}
   \item Undeformed \\image subset
   \end{itemize}
   \end{minipage}
   \vspace{4pt}

    & \ref{sec:basic principles},\ref{sec:sub-pixel}\\
  \midrule
\begin{cpptable}
 getF() 
\end{cpptable}
 &
   \begin{minipage}{1.5in}
    \vspace{4pt}
    \begin{itemize}
   \item Subset center
   \vspace{-10pt}
   \item window size
   \end{itemize}
   \end{minipage}
   \vspace{4pt}
  &   
   \begin{minipage}{1.5in}
    \vspace{4pt}
    \begin{itemize}
   \item Undeformed \\image subset
   \end{itemize}
   \end{minipage}
   \vspace{4pt}

    & \ref{sec:basic principles},\ref{sec:sub-pixel}\\
  \midrule
\begin{cpptable}
 getF() 
\end{cpptable}
 &
   \begin{minipage}{1.5in}
    \vspace{4pt}
    \begin{itemize}
   \item Subset center
   \vspace{-10pt}
   \item window size
   \end{itemize}
   \end{minipage}
   \vspace{4pt}
  &   
   \begin{minipage}{1.5in}
    \vspace{4pt}
    \begin{itemize}
   \item Undeformed \\image subset
   \end{itemize}
   \end{minipage}
   \vspace{4pt}

    & \ref{sec:basic principles},\ref{sec:sub-pixel}\\
  \midrule
\begin{cpptable}
 getF() 
\end{cpptable}
 &
   \begin{minipage}{1.5in}
    \vspace{4pt}
    \begin{itemize}
   \item Subset center
   \vspace{-10pt}
   \item window size
   \end{itemize}
   \end{minipage}
   \vspace{4pt}
  &   
   \begin{minipage}{1.5in}
    \vspace{4pt}
    \begin{itemize}
   \item Undeformed \\image subset
   \end{itemize}
   \end{minipage}
   \vspace{4pt}

    & \ref{sec:basic principles},\ref{sec:sub-pixel}\\
  \midrule
\begin{cpptable}
 getF() 
\end{cpptable}
 &
   \begin{minipage}{1.5in}
    \vspace{4pt}
    \begin{itemize}
   \item Subset center
   \vspace{-10pt}
   \item window size
   \end{itemize}
   \end{minipage}
   \vspace{4pt}
  &   
   \begin{minipage}{1.5in}
    \vspace{4pt}
    \begin{itemize}
   \item Undeformed \\image subset
   \end{itemize}
   \end{minipage}
   \vspace{4pt}

    & \ref{sec:basic principles},\ref{sec:sub-pixel}\\
  \midrule
\begin{cpptable}
 getF() 
\end{cpptable}
 &
   \begin{minipage}{1.5in}
    \vspace{4pt}
    \begin{itemize}
   \item Subset center
   \vspace{-10pt}
   \item window size
   \end{itemize}
   \end{minipage}
   \vspace{4pt}
  &   
   \begin{minipage}{1.5in}
    \vspace{4pt}
    \begin{itemize}
   \item Undeformed \\image subset
   \end{itemize}
   \end{minipage}
   \vspace{4pt}

    & \ref{sec:basic principles},\ref{sec:sub-pixel}\\
  \midrule
\begin{cpptable}
 getF() 
\end{cpptable}
 &
   \begin{minipage}{1.5in}
    \vspace{4pt}
    \begin{itemize}
   \item Subset center
   \vspace{-10pt}
   \item window size
   \end{itemize}
   \end{minipage}
   \vspace{4pt}
  &   
   \begin{minipage}{1.5in}
    \vspace{4pt}
    \begin{itemize}
   \item Undeformed \\image subset
   \end{itemize}
   \end{minipage}
   \vspace{4pt}

    & \ref{sec:basic principles},\ref{sec:sub-pixel}\\
  \midrule
\begin{cpptable}
 getF() 
\end{cpptable}
 &
   \begin{minipage}{1.5in}
    \vspace{4pt}
    \begin{itemize}
   \item Subset center
   \vspace{-10pt}
   \item window size
   \end{itemize}
   \end{minipage}
   \vspace{4pt}
  &   
   \begin{minipage}{1.5in}
    \vspace{4pt}
    \begin{itemize}
   \item Undeformed \\image subset
   \end{itemize}
   \end{minipage}
   \vspace{4pt}

    & \ref{sec:basic principles},\ref{sec:sub-pixel}\\
  \midrule
\begin{cpptable}
 getF() 
\end{cpptable}
 &
   \begin{minipage}{1.5in}
    \vspace{4pt}
    \begin{itemize}
   \item Subset center
   \vspace{-10pt}
   \item window size
   \end{itemize}
   \end{minipage}
   \vspace{4pt}
  &   
   \begin{minipage}{1.5in}
    \vspace{4pt}
    \begin{itemize}
   \item Undeformed \\image subset
   \end{itemize}
   \end{minipage}
   \vspace{4pt}

    & \ref{sec:basic principles},\ref{sec:sub-pixel}\\
  \midrule
\begin{cpptable}
 getF() 
\end{cpptable}
 &
   \begin{minipage}{1.5in}
    \vspace{4pt}
    \begin{itemize}
   \item Subset center
   \vspace{-10pt}
   \item window size
   \end{itemize}
   \end{minipage}
   \vspace{4pt}
  &   
   \begin{minipage}{1.5in}
    \vspace{4pt}
    \begin{itemize}
   \item Undeformed \\image subset
   \end{itemize}
   \end{minipage}
   \vspace{4pt}

    & \ref{sec:basic principles},\ref{sec:sub-pixel}\\
  \midrule
\begin{cpptable}
 getF() 
\end{cpptable}
 &
   \begin{minipage}{1.5in}
    \vspace{4pt}
    \begin{itemize}
   \item Subset center
   \vspace{-10pt}
   \item window size
   \end{itemize}
   \end{minipage}
   \vspace{4pt}
  &   
   \begin{minipage}{1.5in}
    \vspace{4pt}
    \begin{itemize}
   \item Undeformed \\image subset
   \end{itemize}
   \end{minipage}
   \vspace{4pt}

    & \ref{sec:basic principles},\ref{sec:sub-pixel}\\
  \midrule
\begin{cpptable}
 getF() 
\end{cpptable}
 &
   \begin{minipage}{1.5in}
    \vspace{4pt}
    \begin{itemize}
   \item Subset center
   \vspace{-10pt}
   \item window size
   \end{itemize}
   \end{minipage}
   \vspace{4pt}
  &   
   \begin{minipage}{1.5in}
    \vspace{4pt}
    \begin{itemize}
   \item Undeformed \\image subset
   \end{itemize}
   \end{minipage}
   \vspace{4pt}

    & \ref{sec:basic principles},\ref{sec:sub-pixel}\\
  \midrule
\begin{cpptable}
 getF() 
\end{cpptable}
 &
   \begin{minipage}{1.5in}
    \vspace{4pt}
    \begin{itemize}
   \item Subset center
   \vspace{-10pt}
   \item window size
   \end{itemize}
   \end{minipage}
   \vspace{4pt}
  &   
   \begin{minipage}{1.5in}
    \vspace{4pt}
    \begin{itemize}
   \item Undeformed \\image subset
   \end{itemize}
   \end{minipage}
   \vspace{4pt}

    & \ref{sec:basic principles},\ref{sec:sub-pixel}\\
  \midrule
\begin{cpptable}
 getF() 
\end{cpptable}
 &
   \begin{minipage}{1.5in}
    \vspace{4pt}
    \begin{itemize}
   \item Subset center
   \vspace{-10pt}
   \item window size
   \end{itemize}
   \end{minipage}
   \vspace{4pt}
  &   
   \begin{minipage}{1.5in}
    \vspace{4pt}
    \begin{itemize}
   \item Undeformed \\image subset
   \end{itemize}
   \end{minipage}
   \vspace{4pt}

    & \ref{sec:basic principles},\ref{sec:sub-pixel}\\
  \midrule
\begin{cpptable}
 getF() 
\end{cpptable}
 &
   \begin{minipage}{1.5in}
    \vspace{4pt}
    \begin{itemize}
   \item Subset center
   \vspace{-10pt}
   \item window size
   \end{itemize}
   \end{minipage}
   \vspace{4pt}
  &   
   \begin{minipage}{1.5in}
    \vspace{4pt}
    \begin{itemize}
   \item Undeformed \\image subset
   \end{itemize}
   \end{minipage}
   \vspace{4pt}

    & \ref{sec:basic principles},\ref{sec:sub-pixel}\\
  \midrule
\begin{cpptable}
 getF() 
\end{cpptable}
 &
   \begin{minipage}{1.5in}
    \vspace{4pt}
    \begin{itemize}
   \item Subset center
   \vspace{-10pt}
   \item window size
   \end{itemize}
   \end{minipage}
   \vspace{4pt}
  &   
   \begin{minipage}{1.5in}
    \vspace{4pt}
    \begin{itemize}
   \item Undeformed \\image subset
   \end{itemize}
   \end{minipage}
   \vspace{4pt}

    & \ref{sec:basic principles},\ref{sec:sub-pixel}\\
  \midrule
\begin{cpptable}
 getF() 
\end{cpptable}
 &
   \begin{minipage}{1.5in}
    \vspace{4pt}
    \begin{itemize}
   \item Subset center
   \vspace{-10pt}
   \item window size
   \end{itemize}
   \end{minipage}
   \vspace{4pt}
  &   
   \begin{minipage}{1.5in}
    \vspace{4pt}
    \begin{itemize}
   \item Undeformed \\image subset
   \end{itemize}
   \end{minipage}
   \vspace{4pt}

    & \ref{sec:basic principles},\ref{sec:sub-pixel}\\
  \midrule
\begin{cpptable}
 getF() 
\end{cpptable}
 &
   \begin{minipage}{1.5in}
    \vspace{4pt}
    \begin{itemize}
   \item Subset center
   \vspace{-10pt}
   \item window size
   \end{itemize}
   \end{minipage}
   \vspace{4pt}
  &   
   \begin{minipage}{1.5in}
    \vspace{4pt}
    \begin{itemize}
   \item Undeformed \\image subset
   \end{itemize}
   \end{minipage}
   \vspace{4pt}

    & \ref{sec:basic principles},\ref{sec:sub-pixel}\\
  \midrule
\begin{cpptable}
 getF() 
\end{cpptable}
 &
   \begin{minipage}{1.5in}
    \vspace{4pt}
    \begin{itemize}
   \item Subset center
   \vspace{-10pt}
   \item window size
   \end{itemize}
   \end{minipage}
   \vspace{4pt}
  &   
   \begin{minipage}{1.5in}
    \vspace{4pt}
    \begin{itemize}
   \item Undeformed \\image subset
   \end{itemize}
   \end{minipage}
   \vspace{4pt}

    & \ref{sec:basic principles},\ref{sec:sub-pixel}\\
\bottomrule
\end{longtable}

\end{document}
3
  • Same than the other answer... I cant compile this solution! dont knwo why.... Jun 17 '13 at 19:32
  • @AnderBiguri Neither do I: I just copied the example I made and that compiles flawlessly on my machine. Can you be more explicit about what goes wrong?
    – egreg
    Jun 17 '13 at 19:39
  • It seems that I have some problem with my whole document with longtable. In the aisled test there is no problmem with it. Ill open a new question. Jun 18 '13 at 6:45

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.