將數字和表格與一個標籤名稱一起編號

將數字和表格與一個標籤名稱一起編號

我想在圖形和表格的標題中連續使用S.IS.II、等標記我的圖形和表格。S.III

我可以將figuretable標題更改為S.I, ... 通過

\renewcommand{\tablename}{S.}
\renewcommand{\figurename}{S.}
\renewcommand{\thetable}{\Roman{table}}
\renewcommand{\thefigure}{\Roman{figure}}

但這仍然分開計算數字和表格。S.I因此存在兩次,一次用於第一個圖形,一次用於第一個表。

我怎樣才能避免這種情況?謝謝你!

答案1

更新耦合計數器的概念現為xassoccnt1.0 版(目前版本截至 2016 年 8 月 09 日),可在 CTAN/MikTeX 和 TeXLive 2016 上使用。

儘管這個問題的連結中有答案,但我提供了另一個解決方案,其中包含我的xassoccnt包(下一個版本)的實驗代碼。該程式碼目前看起來很長,但它將隱藏在套件中,使用其他巨集當然會減少設定。未來的計劃是擁有一堆「共享」或耦合的計數器,而不是像本例中那樣只有兩個。

注意:這並沒有將\listoftables\listoffigures功能合而為一List of ...(在我看來,這無論如何都會很奇怪)

它適用於hyperref

\documentclass{article}

\usepackage{xassoccnt}
\usepackage{blindtext}


\renewcommand{\tablename}{S.}
\renewcommand{\figurename}{S.}
\renewcommand{\thetable}{\Roman{table}}
\renewcommand{\thefigure}{\Roman{figure}}


\ExplSyntaxOn
\seq_new:N \l__xassoccnt_coupledcounters_seq
\NewDocumentCommand{\DeclareCoupledCounters}{mm}{%
  \seq_clear:N \l__xassoccnt_coupledcounters_seq
  \seq_gput_right:Nn \l__xassoccnt_coupledcounters_seq {#1}
  \seq_gput_right:Nn \l__xassoccnt_coupledcounters_seq {#2}
}

\cs_set_eq:NN \xassoccnt_stepcounter \stepcounter
\cs_set_eq:NN \xassoccnt_setcounter \setcounter % Should be done
\cs_set_eq:NN \xassoccnt_addtocounter \addtocounter % Should be done

\RenewDocumentCommand{\stepcounter}{m}{%
  \tl_set:Nx \l_tmpa_tl {#1}
  \seq_if_in:NVTF \l__xassoccnt_coupledcounters_seq  {\l_tmpa_tl} {%
    \seq_map_inline:Nn \l__xassoccnt_coupledcounters_seq {%
      \xassoccnt_stepcounter{##1}
    }
  }{
    \xassoccnt_stepcounter{#1}% Only step #1 
  }
}
\ExplSyntaxOff


\DeclareCoupledCounters{figure}{table}

\usepackage{hyperref}

\begin{document}
\listoffigures
\listoftables

\section{First}

\blindtext[10]

\begin{figure}

\caption{foo figure}
\end{figure}

\blindtext[10]


\begin{table}
\caption{foo table}
\end{table}

\section{Second}

\blindtext[10]

\begin{figure}

\caption{other foo figure}
\end{figure}

\blindtext[10]


\begin{table}
\caption{other foo table}
\end{table}


\end{document}

在此輸入影像描述

答案2

如果您不需要 hyperref:

\renewcommand{\tablename}{S.}
\renewcommand{\figurename}{S.}
\makeatletter
\let\c@table\c@figure
\makeatother
\renewcommand\thefigure{\Roman{figure}}
\let\thetable\thefigure

相關內容