
Quiero tener una tabla larga como esta:
\begin{center}
\begin{longtable}{|p{2cm}|p{3cm}|p{7cm}|p{3cm}|}
\caption{my caption}
\hline
1 & 2 & 3 & 4\\
\hline
\hline
1 & 2 & 3 & 4\\
\hline
1 & 2 & 3 & 4\\
\hline
.
.
.
1 & 2 & 3 & 4\\
\hline
\label{variability_impl_mech}
\end{longtable}
\end{center}
pero cuando intento compilar esto, aparece este error: !Misplaced \noalign
cuando escribo el título después de la última \hline, funciona bien. Quiero tener el título encima de mi tabla pero aparece este error.
Respuesta1
\begin{longtable}{|p{2cm}|p{3cm}|p{7cm}|p{3cm}|}
\caption{my caption}\\ %%%%<===
\hline
y deberías poner el \label
after \caption
, que tiene más sentido.
Respuesta2
Otra forma: use head y first head:
\documentclass{article}
\usepackage{longtable}
\begin{document}
\begin{longtable}{|p{2cm}|p{3cm}|p{7cm}|p{3cm}|}
\caption{my caption}
\label{variability_impl_mech}
\endfirsthead
\endhead
\hline
1 & 2 & 3 & 4\\
%\hline
\hline
1 & 2 & 3 & 4\\
\hline
1 & 2 & 3 & 4\\
\hline
.
.
.
1 & 2 & 3 & 4\\
\hline
\end{longtable}
\end{document}
Respuesta3
Tuve un problema porque genero mis tablas con la biblioteca pandas de python. De este modo.
print(tabla_1.to_latex(index = False, longtable=True))
Pero el problema es que los pandas generan mis tablas largas de esta manera:
\begin{longtable}{lrrr}
\toprule
Nombre & No datos & P. rango & total\_isnull \\
\midrule
Así que intenté poner \label
y \caption
antes \toprule
, pero nunca se compila. Entonces mi solución fue cambiar \toprule
y \hline
luego tendrás tu compilación, ejemplo:
\begin{longtable}{lrrr}
\label{YourLabel}
\Caption{YourCaption}
\hline
Nombre & No datos & P. rango & total\_isnull \\
\midrule