我是 Latex 的新手,这是来自 wiki latex 教程的创建表格的示例https://en.wikibooks.org/wiki/LaTeX/Tables。
\begin{tabular}{llr}
\hline
\multicolumn{2}{c}{Item} \\
\cline{1-2}
Animal & Description & Price (\$) \\
\hline
Gnat & per gram & 13.65 \\
& each & 0.01 \\
Gnu & stuffed & 92.50 \\
Emu & stuffed & 33.33 \\
Armadillo & frozen & 8.99 \\
\hline
\end{tabular}
我想知道如何在这个例子中为这个表添加具有相同样式的标题
答案1
caption
特殊的字幕格式可以通过该包及其命令实现\captionsetup
。
使用选项将标签与实际标题文本labelsep=newline
分开。Table 1
\documentclass{article}
\usepackage{caption}
\begin{document}
\begin{center}
\captionsetup{justification=centering,labelsep=newline}
\captionof{table}{This is some data} % Or just `\caption{This is some data} if the tabular environment is in a floating environment..
\begin{tabular}{llr}
\hline
\multicolumn{2}{c}{Item} \\
\cline{1-2}
Animal & Description & Price (\$) \\
\hline
Gnat & per gram & 13.65 \\
& each & 0.01 \\
Gnu & stuffed & 92.50 \\
Emu & stuffed & 33.33 \\
Armadillo & frozen & 8.99 \\
\hline
\end{tabular}
\end{center}
\end{document}
编辑
表格下方的第二个“标题”:使用\captionof*{...}{...}
等来防止编号和进入表格列表:
\documentclass{article}
\usepackage{caption}
\begin{document}
\begin{center}
{%
\captionsetup{labelsep=newline}
\captionof{table}{This is some data}
}
\begin{tabular}{llr}
\hline
\multicolumn{2}{c}{Item} \\
\cline{1-2}
Animal & Description & Price (\$) \\
\hline
Gnat & per gram & 13.65 \\
& each & 0.01 \\
Gnu & stuffed & 92.50 \\
Emu & stuffed & 33.33 \\
Armadillo & frozen & 8.99 \\
\hline
\end{tabular}
\captionof*{table}{This is another caption}
\end{center}
\begin{center}
\begin{tabular}{ll}
\hline
foo & foo \tabularnewline
\hline
\end{tabular}
\captionof{table}{Dummy table -- just for checking}
\end{center}
\end{document}