如何为多个表格添加标题

如何为多个表格添加标题

我想为 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

您可以为标签和分隔符定义自定义样式,并在本地应用它。

b

\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

C

\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}

相关内容