![问题图片](https://linux22.com/image/415410/%E9%97%AE%E9%A2%98%E5%9B%BE%E7%89%87.png)
我想显示/获取每个部分达到的计数器的最大值。
到目前为止,我已经找到了一种方法来获取整个文档中计数器的总值/最大值,但我无法使其按部分工作。
这是否可能,也许需要另一个包或者我需要自定义命令?
问题图片
平均能量损失
\documentclass[
paper=a4,
DIV=15,
parskip=half
]{scrartcl}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{
lmodern,
totcount,
comment,
}
%\setcounter{secnumdepth}{0}
\newcounter{counterPERsection}[section]
\regtotcounter{counterPERsection}
\newcounter{anothercounter}
\regtotcounter{anothercounter}
\begin{comment}
\newcommand{\callingcounters}{%
\stepcounter{counterPERsection}\arabic{counterPERsection}\\
\stepcounter{anothercounter}\arabic{anothercounter}.\total{anothercounter}
}
\end{comment}
%%%%%%%%%%%%%%%%%%%%%%
%%% NOT %%%%%%%
%%% WORKING %%%%%%%
%%%%%%%%%%%%%%%%%%%%%%
%\begin{comment}
\newcommand{\callingcounters}{%
\stepcounter{counterPERsection}\arabic{counterPERsection}.\total{counterPERsection}\\
\stepcounter{anothercounter}\arabic{anothercounter}.\total{anothercounter}
}
%\end{comment}
\begin{document}
\section{First section}
\callingcounters
\callingcounters
\callingcounters
\callingcounters
\section{Second section}
\callingcounters
\callingcounters
\end{document}
答案1
您可以使用xcntperchap
为此目的而编写的包。
\documentclass{article}
\usepackage{xcntperchap}
\newcounter{dummy} % for “total” counters
\newcounter{counterPERsection}[section]
\RegisterTrackCounter{section}{counterPERsection}
\newcounter{anothercounter}
\RegisterTrackCounter{dummy}{anothercounter}
% initialize the total counters
\stepcounter{dummy}
\newcommand{\callingcounters}{%
\stepcounter{counterPERsection}%
\arabic{counterPERsection}.%
\ObtainTrackedValueExp{section}{counterPERsection}%
\\*
\stepcounter{anothercounter}\arabic{anothercounter}.%
\ObtainTrackedValueExp{dummy}{anothercounter}%
}
\setlength{\parindent}{0pt} % just for this example
\begin{document}
\section{First section}
\callingcounters
\callingcounters
\callingcounters
\callingcounters
\section{Second section}
\callingcounters
\callingcounters
\end{document}
答案2
\label
您可以使用和的版本来完成此操作\ref
,但您必须手动将计数器值保存在您希望保存它们的位置。 \AtEndDocument
不会削减它。
您可以使用 \currentlabel 来保存几乎任何内容。
\documentclass[
paper=a4,
DIV=15,
parskip=half
]{scrartcl}
%\usepackage[T1]{fontenc}% easier to remove than use
%\usepackage[utf8]{inputenc}
%\usepackage{lmodern, totcount, comment,}
%\setcounter{secnumdepth}{0}
\newcounter{counterPERsection}[section]
\newcounter{anothercounter}
\makeatletter
\newcommand{\currentlabel}[2]{% #1 = text, #2 = label name
\edef\@currentlabel{#1}%
\label{#2}%
}
\makeatother
\newcommand{\callingcounters}[2]{% #1 = total counterPERsection, #2 = total anothercounter
\stepcounter{counterPERsection}\arabic{counterPERsection}.#1\\
\stepcounter{anothercounter}\arabic{anothercounter}.#2
}
%\end{comment}
\begin{document}
\section{First section}
\callingcounters{\ref{CPS1}}{\ref{AC}}
\callingcounters{\ref{CPS1}}{\ref{AC}}
\callingcounters{\ref{CPS1}}{\ref{AC}}
\callingcounters{\ref{CPS1}}{\ref{AC}}
\currentlabel{\thecounterPERsection}{CPS1}
\section{Second section}
\callingcounters{\ref{CPS2}}{\ref{AC}}
\callingcounters{\ref{CPS2}}{\ref{AC}}
\currentlabel{\thecounterPERsection}{CPS2}
\currentlabel{\theanothercounter}{AC}
\end{document}