3

I have the below mentioned code and it is giving me caption outside float error. Kindly advise as to why am I getting this error.

\begin{center}
\caption{
Table 10. Performance for the seven models using the top 10 features from model D3 on the test dataset. \label{long}}\\
\vspace{15}
\begin{tabular}{|c c c|} 
 \hline
 Models & AUC & RMSE  \\ [0.5ex] 
 \hline\hline
M1 & 0.640431 & 0.459820 \\
 \hline\hline
M2 & 0.980599 & 0.179471 \\
 \hline\hline
M3 & 0.985183 & 0.112334 \\
 \hline\hline
D1 & 0.712025 & 0.158077 \\
 \hline\hline
D2 & 0.838344 & 0.120950 \\
 \hline\hline
D3 & 0.753037 & 0.117660 \\
 \hline\hline
D4 & 0.711824 & 0.814445\\
 \hline
\end{tabular}
\vspace{15pt}
\end{center}
2
  • 1
    Welcome to TeX.SE! You can use captionof{table}{<caption text>} defined in in the packages caption and capt-of.
    – Zarko
    Jun 29, 2021 at 23:54
  • 1
    To answer your question, you get that error message because \@captype is undefined (instead of figure or table). Jun 30, 2021 at 4:30

1 Answer 1

3

Just wrap your tabular environment in a table environment which is a floating entity that can have caption and label.

\documentclass{article}

\begin{document}
    \listoftables
    
    \vspace{2cm}
    
    \begin{table}[ht]
        \centering
        \begin{tabular}{|c c c|} 
            \hline
            Models & AUC & RMSE  \\ [0.5ex] 
            \hline\hline
            M1 & 0.640431 & 0.459820 \\
            \hline\hline
            M2 & 0.980599 & 0.179471 \\
            \hline\hline
            M3 & 0.985183 & 0.112334 \\
            \hline\hline
            D1 & 0.712025 & 0.158077 \\
            \hline\hline
            D2 & 0.838344 & 0.120950 \\
            \hline\hline
            D3 & 0.753037 & 0.117660 \\
            \hline\hline
            D4 & 0.711824 & 0.814445\\
            \hline
        \end{tabular}
        %Previous method: \renewcommand\thetable{10} %If you want to change the table number manually
        \setcounter{table}{9} %If you want to change the table number manually
        \caption{Performance for the seven models using the top 10 features from model D3 on the test dataset.}
        \label{table::long}
    \end{table}
    
    This is a reference, \ref{table::long}.
\end{document}

Edit: Added \centering which I forgot to do, and changed the method of renumbering. Thanks to @Mico's comments.

enter image description here

3
  • 1
    To replicate the horizontal centering performed in OP's code, you should provide a \centering directive between \begin{table} and \begin{tabular}.
    – Mico
    Jun 30, 2021 at 0:59
  • 2
    Setting the table counter to a constant, via \renewcommand\thetable{10}, is poor advice to future readers of your posting. Running \setcounter{table}{9} is much less likely to be misunderstood.
    – Mico
    Jun 30, 2021 at 1:02
  • @Mico Good points.
    – Aria
    Jun 30, 2021 at 3:48

You must log in to answer this question.

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