Search code examples
latexpdflatex

How to put a caption on top of Latex table


I want to put a caption on top of the following table in Latex.

\begin{center}

\begin{tabular}{ | l | l | l | l | l | l | l | l | l | p{5cm} |}
\hline
GT & MT & PT & ML & FP & FN & ID & FM & Rc & Pr \\ \hline
abc & abc & abc & abc & abc & abc & abc & abc & abc & abc \\ \hline

\hline
\end{tabular}

\end{center}

Solution

  • You do not make a table, but only a tabular (which cannot have a caption). You have to make a table first, and then a tabular:

    \begin{table}[htb]
    
        \centering % instead of \begin{center}
        \caption{Here you can type in your caption}
        \vspace{10mm} % Adjust the height of the space between caption and tabular
    
        \begin{tabular}{ | l | l | l | l | l | l | l | l | l | p{5cm} |}
            \hline
            GT & MT & PT & ML & FP & FN & ID & FM & Rc & Pr \\ \hline
            abc & abc & abc & abc & abc & abc & abc & abc & abc & abc \\ \hline
             \hline
        \end{tabular}
    
    \end{table}
    

    Further explanation: "The table environment merely holds our other environments and allows to add a caption to our table. The actual data is contained in the tabular environment and we center the table on the page using the center environment."