0

Is there any way to place \caption{} in front of \begin{longtable}? Illustrating with an example, instead of

\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}

I would like to use something like

\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}
2
  • Don't show only snippets. Extend your example to a full document which can be compiled directly. Commented Mar 5, 2019 at 10:37
  • OK, sorry. I completed my example to a compilable form.
    – Roli
    Commented Mar 5, 2019 at 10:40

1 Answer 1

1

You can do it with \captionof. Be aware that page breaks between the caption and the longtable are possible here.

\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}

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .