How to reset counter each section with secnumdepth set to 0
You can step the counter for section
, but suppress its output:
\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}
This will need actions also on the headers, if you use them.
Alternative way: patch \section
so it steps the relevant counter.
\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}
Today a new prerelease of KOMA-Script version 3.31 was published. It can be installed from the KOMA-Script website. With this version
\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}
results in
If you only want to suppress the section number in document, page header and TOC, you can use:
\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
This works with really old versions too. Example:
\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}
Result: