如何在Latex表格上方添加标题

13

我想在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}

请使用[tex.se]提出纯LaTeX问题。 - Adriaan
1个回答

23

你没有创建一个表格,而是只创建了一个tabular(该类型不支持标题)。你需要先创建一个表格,然后再在其中加入一个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}

更多解释: "表格环境仅包含其他环境并允许向表格添加标题。实际数据包含在tabular环境中,并使用center环境将表格居中在页面上。"


非常感谢,它起作用了。如何在标题和表格之间放置一个空格?我正在尝试使用\hline,但它显示错误。 - Mazhar Mohsin
可以使用 vspace 在标题和表格之间创建空白。请查看我的更新答案 :) - Nander Speerstra
2
\hline在表格中是用来在表格里的,而不是在表格外的(这是一个困难但重要的区别)。 - Nander Speerstra
因为我在SO上已经写了大约十次,所以我也为\centering % instead of \begin{center}投上了一票。此外,单独使用[h]应该避免:最好使用[htb] - MattAllegro
@MattAllegro,你是对的!我已经编辑了放置选项。 - Nander Speerstra

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接