标题中的章节编号和表格编号之间的连字符

标题中的章节编号和表格编号之间的连字符

使用该chngcntr包,可以从当前部分开始对表格和图形进行编号(即第三部分的第二个表格将是表 3.2)。我的大学希望将部分和表格编号之间的分隔符改为连字符:

Table 3.2应该是Table 3-2

我该如何实现这个目标?

以下是一个直观的例子:

\documentclass{article}

\usepackage{tabularx}
\usepackage{chngcntr}
\usepackage{booktabs}
\usepackage{float}

\counterwithin{figure}{section}
\counterwithin{table}{section}

\begin{document}

\section{This is the first section}

\begin{table}[H]
  \centering
  \caption{This should write ''Table 1-1``}
  \begin{tabular}{lll}
    \toprule
    A & B & C \\
    \toprule
    D & E & F \\
    G & H & I \\
    \bottomrule
  \end{tabular}
\end{table}

\begin{table}[H]
  \centering
  \caption{This should write ''Table 1-2``}
  \begin{tabular}{lll}
    \toprule
    A & B & C \\
    \toprule
    D & E & F \\
    G & H & I \\
    \bottomrule
  \end{tabular}
\end{table}

\section{This is the second section}

\begin{table}[H]
  \centering
  \caption{This should write ''Table 2-1``}
  \begin{tabular}{lll}
    \toprule
    A & B & C \\
    \toprule
    D & E & F \\
    G & H & I \\
    \bottomrule
  \end{tabular}
\end{table}

\begin{table}[H]
  \centering
  \caption{This should write ''Table 2-2``}
  \begin{tabular}{lll}
    \toprule
    A & B & C \\
    \toprule
    D & E & F \\
    G & H & I \\
    \bottomrule
  \end{tabular}
\end{table}

\end{document}

在此处输入图片描述

答案1

您需要提供说明

\renewcommand{\thefigure}{\thesection-\arabic{figure}}
\renewcommand{\thetable}{\thesection-\arabic{table}}

在序言中。


在此处输入图片描述

\documentclass{article}
\usepackage{booktabs}

\counterwithin{figure}{section}
\counterwithin{table}{section}

\renewcommand{\thefigure}{\thesection-\arabic{figure}}
\renewcommand{\thetable}{\thesection-\arabic{table}}

\begin{document}

\section{This is the first section}

\begin{table}[ht]
  \centering
  \caption{This should be ``Table 1-1''\strut}
  \begin{tabular}{lll}
    \toprule
    A & B & C \\
    \midrule
    D & E & F \\
    G & H & I \\
    \bottomrule
  \end{tabular}
\end{table}

\begin{table}[ht]
  \centering
  \caption{This should be ``Table 1-2''\strut}
  \begin{tabular}{lll}
    \toprule
    A & B & C \\
    \midrule
    D & E & F \\
    G & H & I \\
    \bottomrule
  \end{tabular}
\end{table}

\section{This is the second section}

\begin{figure}[ht]
  \centering
  \caption{This should be ``Figure 2-1''\strut}
  \rule{4cm}{2cm}
\end{figure}

\begin{table}[ht!]
  \centering
  \caption{This should be ``Table 2-1''\strut}
  \begin{tabular}{lll}
    \toprule
    A & B & C \\
    \midrule
    D & E & F \\
    G & H & I \\
    \bottomrule
  \end{tabular}
\end{table}

\end{document}

相关内容