如何將「\caption{}」放在「\begin{longtable}」前面?

如何將「\caption{}」放在「\begin{longtable}」前面?

有什麼辦法可以放在\caption{}前面嗎\begin{longtable}?用一個例子來說明,而不是

\documentclass{article}
\usepackage{longtable}
\begin{document}
\begin{longtable}{c|c|c|c}
\caption{This is a very nice table}
A & B & A & B \\ \hline
\end{longtable}
\end{document}

我想用類似的東西

\documentclass{article}
\usepackage{longtable}
\begin{document}
\caption{This is a very nice table}
\begin{longtable}{c|c|c|c}
A & B & A & B \\ \hline
\end{longtable}
\end{document}

答案1

你可以用 來做到這一點\captionof。請注意,標題和長表之間可能存在分頁符號。

\documentclass{article}
\usepackage{longtable}
\usepackage{caption}


\begin{document}

\captionof{table}{This is a very nice table}
\begin{longtable}{c|c|c|c}
A & B & A & B \\ \hline
\end{longtable}
\addtocounter{table}{-1}

\captionof{table}{This is a very nice table}
\begin{longtable}{c|c|c|c}
A & B & A & B \\ \hline
\end{longtable}

\end{document}

在此輸入影像描述

相關內容