平均能量损失

平均能量损失

我正在使用 KOMA 类 scrartcl 编写文档。我\setcounter{secnumdepth}{0}在开始时启用了此功能,因为我打算使用其他类型的编号,将其写入节标题本身。

不幸的是,这会影响计数器的重置,因为部分计数器不再“激活”(缺乏更好的术语)。

这是否可以做到,即保留上述选项但仍重置每个部分的计数器?

平均能量损失

\documentclass[
paper=a4,
DIV=15,
parskip=half
]{scrartcl}

\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{lmodern}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% the problematic option %%%
\setcounter{secnumdepth}{0}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\newcounter{thatimportantc}[section]
\newcounter{randomcounter}

\newcommand{\callingcounters}{%
    \stepcounter{thatimportantc}\arabic{thatimportantc}~|~%
    \stepcounter{randomcounter}\arabic{randomcounter}
}

\begin{document}
    
\section{The first section}

In this section, you will observe that the counters are equal (as expected).

\callingcounters\\
\callingcounters

\section{The second section}

In this section, you will observe that the counters are equal (as expected).

\callingcounters\\
\callingcounters

The option to count up section numbers will now be changed via: \verb+\setcounter{secnumdepth}{2}+ \setcounter{secnumdepth}{2}

The counter \verb+thatimportantc+ will now be reset with each section. From hereon forth, you will observe that the counters are not equal anymore.

\section{Third section}

\callingcounters\\
\callingcounters

\section{4th section}

\callingcounters

\end{document}

答案1

您可以步进计数器section,但抑制其输出:

\documentclass[
paper=a4,
DIV=15,
parskip=half
]{scrartcl}

\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{lmodern}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% the problematic option %%%
\setcounter{secnumdepth}{1}
\makeatletter
\renewcommand{\@seccntformat}[1]{}
\makeatother
%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\newcounter{thatimportantc}[section]
\newcounter{randomcounter}

\newcommand{\callingcounters}{%
    \stepcounter{thatimportantc}\arabic{thatimportantc}~|~%
    \stepcounter{randomcounter}\arabic{randomcounter}
}

\begin{document}

\section{The first section}

In this section, you will observe that the counters are equal (as expected).

\callingcounters\\
\callingcounters

\section{The second section}

In this section, you will observe that the counters are not equal (as expected).

\callingcounters\\
\callingcounters

\section{Third section}

\callingcounters\\
\callingcounters

\section{4th section}

\callingcounters

\end{document}

在此处输入图片描述

如果您使用标题,这也需要对其采取行动。

替代方法:修补程序\section,以便它能够步进相关计数器。

\documentclass[
paper=a4,
DIV=15,
parskip=half
]{scrartcl}

\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{lmodern}
\usepackage{etoolbox}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% the problematic option %%%
\setcounter{secnumdepth}{0}
\preto\section{\stepcounter{section}}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%


\newcounter{thatimportantc}[section]
\newcounter{randomcounter}

\newcommand{\callingcounters}{%
    \stepcounter{thatimportantc}\arabic{thatimportantc}~|~%
    \stepcounter{randomcounter}\arabic{randomcounter}
}

\begin{document}

\section{The first section}

In this section, you will observe that the counters are equal (as expected).

\callingcounters\\
\callingcounters

\section{The second section}

In this section, you will observe that the counters are not equal (as expected).

\callingcounters\\
\callingcounters

\section{Third section}

\callingcounters\\
\callingcounters

\section{4th section}

\callingcounters

\end{document}

答案2

今天发布了 KOMA-Script 3.31 版的新预发布版。可以从KOMA-Script 网站. 使用此版本

\documentclass[
%paper=a4,% default
DIV=15,
parskip=half
]{scrartcl}[2020/06/02]
\usepackage[T1]{fontenc}
%\usepackage[utf8]{inputenc}% only needed with older TeX distributions
\usepackage{lmodern}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% the problematic option %%%
\setcounter{secnumdepth}{0}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\newcounter{thatimportantc}[section]
\newcounter{randomcounter}

\newcommand{\callingcounters}{%
  \stepcounter{thatimportantc}\arabic{thatimportantc}~|~%
  \stepcounter{randomcounter}\arabic{randomcounter}
}

\begin{document}
\KOMAScriptVersion% show the KOMA-Script version used for the example
\tableofcontents
\section{The first section}
In this section, you will observe that the counters are equal (as expected).

\callingcounters\\
\callingcounters

\section{The second section}
In this section, you will observe that the counters are not equal (as expected).

\callingcounters\\
\callingcounters

\section{Third section}
\callingcounters\\
\callingcounters

\section{4th section}
\callingcounters

\end{document}

结果是

在此处输入图片描述

如果只想抑制文档、页眉和目录中的章节编号,可以使用:

\setcounter{secnumdepth}{\sectionnumdepth}
\renewcommand*{\sectionformat}{}% supress section number in document body
\renewcommand*{\sectionmarkformat}{}% supress section number in page header
\renewcommand*{\addsectiontocentry}[2]{\addtocentrydefault{section}{}{#2}}% supress section number in ToC

这也适用于非常旧的版本。例如:

\documentclass[
%paper=a4,% default
DIV=15,
parskip=half
]{scrartcl}
\usepackage[T1]{fontenc}
%\usepackage[utf8]{inputenc}% only needed with older TeX distributions
\usepackage{lmodern}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% the problematic option %%%
\setcounter{secnumdepth}{\sectionnumdepth}
\renewcommand*{\sectionformat}{}% supress section number in document body
\renewcommand*{\sectionmarkformat}{}% supress section number in page header
\renewcommand*{\addsectiontocentry}[2]{\addtocentrydefault{section}{}{#2}}% supress section number in ToC
%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\newcounter{thatimportantc}[section]
\newcounter{randomcounter}

\newcommand{\callingcounters}{%
  \stepcounter{thatimportantc}\arabic{thatimportantc}~|~%
  \stepcounter{randomcounter}\arabic{randomcounter}
}

\begin{document}
\KOMAScriptVersion% show the KOMA-Script version used for the example
\tableofcontents
\section{The first section}
In this section, you will observe that the counters are equal (as expected).

\callingcounters\\
\callingcounters

\section{The second section}
In this section, you will observe that the counters are not equal (as expected).

\callingcounters\\
\callingcounters

\section{Third section}
\callingcounters\\
\callingcounters

\section{4th section}
\callingcounters

\end{document}

结果:

在此处输入图片描述

相关内容