我正在写一个包含多个复杂内容的长表。当我意识到我需要一个多页表时,我尝试将其更改table
为longtable
,但它只会给我带来很多错误。
我怎样才能获得多个页表?
带有普通表的代码:
\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}
我已尝试过:
\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}
答案1
更像这样(尽管对于页面来说它仍然太宽)
\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}
答案2
环境longtable
会创建表,因此它tabular
里面不应该有。您可以这样做;请查看软件包手册以了解其他调整。
\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}