![如何为多个表格添加标题](https://linux22.com/image/454512/%E5%A6%82%E4%BD%95%E4%B8%BA%E5%A4%9A%E4%B8%AA%E8%A1%A8%E6%A0%BC%E6%B7%BB%E5%8A%A0%E6%A0%87%E9%A2%98.png)
我想为 4 个表格添加标题。标签应为“表1-4:标题”。我的表格如下所示:
\begin{tabular}{c|c}
1&2\\
3&4
\end{tabular}
\begin{tabular}{c|c}
5&6\\
7&8
\end{tabular}
\begin{tabular}{c|c}
1&2\\
3&4
\end{tabular}
\begin{tabular}{c|c}
5&6\\
7&8
\end{tabular}
\captionof{table}{caption}
答案1
您可以为标签和分隔符定义自定义样式,并在本地应用它。
\documentclass[12pt,a4paper]{article}
\usepackage{caption}
\DeclareCaptionLabelFormat{customstyle}{\textbf{tabular 1-4}}
\DeclareCaptionLabelSeparator{customstyle}{\textbf{:}\space}
\begin{document}
\centering
\begin{tabular}{c|c}
1&2\\
3&4
\end{tabular}
\begin{tabular}{c|c}
5&6\\
7&8
\end{tabular}
\begin{tabular}{c|c}
1&2\\
3&4
\end{tabular}
\begin{tabular}{c|c}
5&6\\
7&8
\end{tabular}
{\captionsetup[table]{labelformat=customstyle,labelsep=customstyle}
\captionof{table}{caption}}
\bigskip
\begin{tabular}{c|c}
1&2\\
3&4
\end{tabular}
\begin{tabular}{c|c}
5&6\\
7&8
\end{tabular}
\begin{tabular}{c|c}
1&2\\
3&4
\end{tabular}
\begin{tabular}{c|c}
5&6\\
7&8
\end{tabular}
\captionof{table}{caption}
\end{document}
选项 2
假设第一个数字(1-4 中的)表示集合的数量,第二个数字表示表格的数量,您可以使用以下方式在本地设置第二个数字\notabs
\documentclass{article}
\usepackage{caption}
\newcounter{nrotabs}% to set the numbers of tabulars <<<<
\DeclareCaptionLabelFormat{customstyle}{\bfseries tabular #2}
\DeclareCaptionLabelSeparator{customstyle}{\bfseries -\thenrotabs:\space}
\begin{document}
\centering
\begin{tabular}{c|c}
1&2\\
3&4
\end{tabular}
\begin{tabular}{c|c}
5&6\\
7&8
\end{tabular}
\begin{tabular}{c|c}
1&2\\
3&4
\end{tabular}
\begin{tabular}{c|c}
5&6\\
7&8
\end{tabular}
{\setcounter{nrotabs}{4}% set the numbers of tabulars
\captionsetup[table]{labelformat=customstyle,labelsep=customstyle}
\captionof{table}{caption x 4}}
\bigskip
\begin{tabular}{c|c}
1&2\\
3&4
\end{tabular}
\begin{tabular}{c|c}
5&6\\
7&8
\end{tabular}
{\setcounter{nrotabs}{2}% set the numbers of tabulars
\captionsetup[table]{labelformat=customstyle,labelsep=customstyle}
\captionof{table}{caption x 2}}
\end{document}