我想在方程参考计数器中使用节号。
这通常\numberwithin
需要amsmath
包裹。
我想在文档中更改这些参考文献的章节编号深度。
这需要\counterwithin
来自chngcntr
包裹。
问题:
我想改变\counterwithin
计数器输出的语法,使得超出最深部分深度的符号是连字符而不是句点:
- 实际:[节]。[小节]。[小小节]。[方程编号]
- 所需:[节] . [子节] . [子子节] – [方程编号]
重要的提示:
方程编号方案的截面深度应随级别的深度而变化。因此,我计划采用如下方案:
- 公式 1.1-1
- 公式 1.2-1
- 公式 1.3.1-1
- 公式 1.4-1
- 公式 2-1
- 公式 3.1-1
检查文档:
这chngcntr
包装文档相当薄弱。
这amsmath
文档[第 9 页]指出,只需更新计数器代码:
\renewcommand{\theequation}{\thesection–\arabic{equation}}
如果不重置,就会产生问题。此外,此代码不是万能的,因为整个文档中的节深度都会发生变化,这使得万能的命令变得更加困难。
MWE描述:
在代码中,用户创建的命令中的代码\equationNumbering
似乎没有简单的方法来删除.
后面\thesubsubsection
(或最深的部分)并在其位置添加连字符。
MWE,更新了 Hupfen 的本地答案和 Werner 的答案这里:
\documentclass{scrartcl}
\usepackage{geometry} % margin/page layout settings
\usepackage{scrlayer-scrpage} % improved header commands. [supercedes `fancyhdr' package].
\usepackage{mathtools} % includes amsmath, supplements it.
\usepackage{chngcntr} % allows changing equation section depth mid-document
\usepackage{etoolbox}
% Margin Settings:
\KOMAoptions{fontsize = 12pt ,
parskip = half- ,
headheight = 1.000em ,
footheight = 2.700em ,
DIV = current }
\geometry{letterpaper ,
hmargin = 0.750in ,
tmargin = 0.750in ,
bmargin = 0.750in ,
headsep = 1.000em ,
footskip = 3.700em } % [ = Footheight + Footsep]
%Initialize headers and footers
\chead{\normalfont Header 1 \\ Header 2}
\cfoot{\normalfont Footer 1 \\ Footer 2}
\ofoot{\normalfont Page \thepage}
% Section numbering: Format \paragraph like \subsection
\newcommand{ \subsubsubsection} [1] { \paragraph{#1} }
\newcommand{\subsubsubsubsection} [1] { \subparagraph{#1} }
\setcounter{secnumdepth}{5}
\makeatletter
\renewcommand{\paragraph} %
{\@startsection{paragraph}{4}{\z@} %
{-2.5ex\@plus -1ex \@minus -.25ex} %
{1.25ex \@plus .25ex} %
{\normalfont\sffamily\normalsize\bfseries} }
\renewcommand{\subparagraph} %
{\@startsection{subparagraph}{4}{\z@} %
{-2.5ex\@plus -1ex \@minus -.25ex} %
{1.25ex \@plus .25ex} %
{\normalfont\sffamily\normalsize\bfseries} }
\makeatother
\let\origtheequation\theequation
% Equation Numbering
\counterwithin*{equation}{section} % Reset equation at \section
\counterwithin*{equation}{subsection} % Reset equation at \subsection
\counterwithin*{equation}{subsubsection} % Reset equation at \subsubsection
\counterwithin*{equation}{paragraph} % Reset equation at \paragraph
\counterwithin*{equation}{subparagraph} % Reset equation at \subparagraph
\newcommand{\xequationFormat} {\determineSection-\arabic{equation}}
\newcommand{\determineSection}{
\ifnum\value{subsection} > 0
\ifnum\value{subsubsection} > 0
\ifnum\value{paragraph} > 0
\ifnum\value{subparagraph} > 0 \thesubparagraph
\else \theparagraph \fi
\else \thesubsubsection \fi
\else \thesubsection \fi
\else \thesection \fi
}
\begin{document}
\setcounter{section}{-1}
\let\theequation\origtheequation
\section{Level 1}
\begin{equation} x \end{equation}
\begin{equation} x \end{equation}
\subsection{Level 2}
\begin{equation} x \end{equation}
\begin{equation} x \end{equation}
\subsubsection{Level 3}
\begin{equation} x \end{equation}
\begin{equation} x \end{equation}
\subsubsubsection{Level 4}
\begin{equation} x \end{equation}
\begin{equation} x \end{equation}
\subparagraph{Level 5}
\begin{equation} x \end{equation}
\begin{equation} x \end{equation}
\clearpage
\let\theequation\xequationFormat
\section{Level 1}
\begin{equation} x \end{equation}
\begin{equation} x \end{equation}
\subsection{Level 2}
\begin{equation} x \end{equation}
\begin{equation} x \end{equation}
\subsubsection{Level 3}
\begin{equation} x \end{equation}
\begin{equation} x \end{equation}
\subsubsubsection{Level 4}
\begin{equation} x \end{equation}
\begin{equation} x \end{equation}
\subparagraph{Level 5}
\begin{equation} x \end{equation}
\begin{equation} x \end{equation}
\clearpage
\section{Level 1}
\begin{equation} x \end{equation}
\begin{equation} x \end{equation}
\subsection{Level 2}
\begin{equation} x \end{equation}
\begin{equation} x \end{equation}
\subsubsection{Level 3}
\begin{equation} x \end{equation}
\begin{equation} x \end{equation}
\subsubsubsection{Level 4}
\begin{equation} x \end{equation}
\begin{equation} x \end{equation}
\subparagraph{Level 5}
\begin{equation} x \end{equation}
\begin{equation} x \end{equation}
\end{document}
原始 MWE:
\documentclass{scrartcl}
\usepackage{geometry} % margin/page layout settings
\usepackage{scrlayer-scrpage} % improved header commands. [supercedes `fancyhdr' package].
\usepackage{mathtools} % includes amsmath, supplements it.
\usepackage{chngcntr} % allows changing equation section depth mid-document
% Margin Settings:
\newlength{\xhmargin } \setlength{\xhmargin }{0.750in}
\newlength{\xtmargin } \setlength{\xtmargin }{0.750in}
\newlength{\xbmargin } \setlength{\xbmargin }{0.750in}
\newlength{\xheadheight} \setlength{\xheadheight}{2.700em}
\newlength{\xheadsep } \setlength{\xheadsep }{1.000em}
\newlength{\xfootheight} \setlength{\xfootheight}{2.700em}
\newlength{\xfootskip } \setlength{\xfootskip }{3.700em} % [ = Footheight + Footsep]
\KOMAoptions{fontsize = 12pt ,
parskip = half- ,
headheight = \xheadheight ,
footheight = \xfootheight ,
DIV = current }
\geometry{letterpaper ,
hmargin = \xhmargin ,
tmargin = \xtmargin ,
bmargin = \xbmargin ,
headsep = \xheadsep ,
footskip = \xfootskip }
%Initialize headers and footers
\chead{\normalfont Header 1 \\ Header 2}
\cfoot{\normalfont Footer 1 \\ Footer 2}
\ofoot{\normalfont Page \thepage}
\counterwithin{equation}{section}
\newcommand{\equationNumbering} [2] { \counterwithout{equation}{#1}\counterwithin{equation}{#2} }
% syntax: \equationNumbering{oldSectionDepth}{newSectionDepth}
% Section numbering: Section depth
\setcounter{secnumdepth}{5}
% Section numbering: Format \paragraph like \subsection
\newcommand{\subsubsubsection} [1] { \paragraph{#1} }
\makeatletter
\renewcommand{\paragraph} %
{\@startsection{paragraph}{4}{\z@} %
{-2.5ex\@plus -1ex \@minus -.25ex} %
{1.25ex \@plus .25ex} %
{\normalfont\sffamily\normalsize\bfseries} }
\makeatother
\begin{document}
\section{Item I}
\equationNumbering{section}{subsubsection}
\clearpage
\subsection{A}
\subsubsection{x}
\begin{equation} x \end{equation}
\begin{equation} x \end{equation}
\subsubsection{y}
\begin{equation} x \end{equation}
\begin{equation} x \end{equation}
\subsubsection{z}
\begin{equation} x \end{equation}
\begin{equation} x \end{equation}
\clearpage
\subsection{B}
\subsubsection{x}
\begin{equation} x \end{equation}
\begin{equation} x \end{equation}
\subsubsection{y}
\begin{equation} x \end{equation}
\begin{equation} x \end{equation}
\subsubsection{z}
\begin{equation} x \end{equation}
\begin{equation} x \end{equation}
\equationNumbering{subsubsection}{section}
\clearpage
\section{Item II}
\equationNumbering{section}{paragraph}
\clearpage
\subsection{Item IIa}
\clearpage
\subsubsection{A}
\subsubsubsection{x}
\begin{equation} x \end{equation}
\begin{equation} x \end{equation}
\subsubsubsection{y}
\begin{equation} x \end{equation}
\begin{equation} x \end{equation}
\subsubsubsection{z}
\begin{equation} x \end{equation}
\begin{equation} x \end{equation}
\clearpage
\subsubsection{B}
\subsubsubsection{x}
\begin{equation} x \end{equation}
\begin{equation} x \end{equation}
\subsubsubsection{y}
\begin{equation} x \end{equation}
\begin{equation} x \end{equation}
\subsubsubsection{z}
\begin{equation} x \end{equation}
\begin{equation} x \end{equation}
\clearpage
\subsubsection{C}
\subsubsubsection{x}
\subsubsubsection{y}
\subsubsubsection{z}
\clearpage
\subsection{Item IIb}
\clearpage
\subsubsection{A}
\subsubsubsection{x}
\begin{equation} x \end{equation}
\begin{equation} x \end{equation}
\subsubsubsection{y}
\begin{equation} x \end{equation}
\begin{equation} x \end{equation}
\subsubsubsection{z}
\begin{equation} x \end{equation}
\begin{equation} x \end{equation}
\clearpage
\subsubsection{B}
\subsubsubsection{x}
\begin{equation} x \end{equation}
\begin{equation} x \end{equation}
\subsubsubsection{y}
\begin{equation} x \end{equation}
\begin{equation} x \end{equation}
\subsubsubsection{z}
\begin{equation} x \end{equation}
\begin{equation} x \end{equation}
\clearpage
\subsubsection{C}
\subsubsubsection{x}
\subsubsubsection{y}
\subsubsubsection{z}
\equationNumbering{paragraph}{section}
\clearpage
\section{Item IV}
\equationNumbering{section}{subsection}
\clearpage
\subsection{x}
\begin{equation} x \end{equation}
\begin{equation} x \end{equation}
\subsection{y}
\begin{equation} x \end{equation}
\begin{equation} x \end{equation}
\subsection{z}
\begin{equation} x \end{equation}
\begin{equation} x \end{equation}
\end{document}
答案1
我重新定义了\theequation
一些关于计数器值的查询:
\renewcommand{\theequation}{%
\ifnum\value{subsection} > 0
\ifnum\value{subsubsection} > 0
\thesubsubsection-\arabic{equation}
\else
\thesubsection-\arabic{equation}
\fi
\else
\thesection-\arabic{equation}
\fi
}
我将方程计数器的重置改为subsubsection
。
\subsubsection
如果 a在没有 before 的情况下出现,则此操作无效\subsection
。
以下是完整代码
\documentclass{scrartcl}
\usepackage{geometry} % margin/page layout settings
\usepackage{scrlayer-scrpage} % improved header commands. [supercedes `fancyhdr' package].
\usepackage{mathtools} % includes amsmath, supplements it.
\usepackage{chngcntr} % allows changing equation section depth mid-document
% Margin Settings:
\newlength{\xhmargin } \setlength{\xhmargin }{0.750in}
\newlength{\xtmargin } \setlength{\xtmargin }{0.750in}
\newlength{\xbmargin } \setlength{\xbmargin }{0.750in}
\newlength{\xheadheight} \setlength{\xheadheight}{2.700em}
\newlength{\xheadsep } \setlength{\xheadsep }{1.000em}
\newlength{\xfootheight} \setlength{\xfootheight}{2.700em}
\newlength{\xfootskip } \setlength{\xfootskip }{3.700em} % [ = Footheight + Footsep]
\KOMAoptions{fontsize = 12pt ,
pars
kip = half- ,
headheight = \xheadheight ,
footheight = \xfootheight ,
DIV = current }
\geometry{letterpaper ,
hmargin = \xhmargin ,
tmargin = \xtmargin ,
bmargin = \xbmargin ,
headsep = \xheadsep ,
footskip = \xfootskip }
%Initialize headers and footers
\chead{\normalfont Header 1 \\ Header 2}
\cfoot{\normalfont Footer 1 \\ Footer 2}
\ofoot{\normalfont Page \thepage}
\counterwithin{equation}{subsubsection} % Reset with \subsubsection
\let\origtheequation\theequation
%
\renewcommand{\theequation}{%
\ifnum\value{subsection} > 0
\ifnum\value{subsubsection} > 0
\thesubsubsection-\arabic{equation}
\else
\thesubsection-\arabic{equation}
\fi
\else
\thesection-\arabic{equation}
\fi
}
% Section numbering: Table of contents and section depth
\setcounter{secnumdepth}{5}
% Section numbering: Format \paragraph like \subsection
\newcommand{\subsubsubsection} [1] { \paragraph{#1} }
\makeatletter
\renewcommand{\paragraph} %
{\@startsection{paragraph}{4}{\z@} %
{-2.5ex\@plus -1ex \@minus -.25ex} %
{1.25ex \@plus .25ex} %
{\normalfont\sffamily\normalsize\bfseries} }
\makeatother
\begin{document}
\section{Item I}
\begin{equation}
x
\end{equation}
\begin{equation}
x
\end{equation}
\subsection{First sub}
\begin{equation}
x \label{first}
\end{equation}
\clearpage
\subsection{A}
\subsubsection{x}
\begin{equation} x \end{equation}
\begin{equation} x \end{equation}
\subsubsection{y}
\begin{equation} x \end{equation}
\begin{equation} x \end{equation}
\subsubsection{z}
\begin{equation} x \end{equation}
\begin{equation} x \end{equation}
\clearpage
\subsection{B}
\subsubsection{x}
\begin{equation} x \end{equation}
\begin{equation} x \end{equation}
\subsubsection{y}
\begin{equation} x \end{equation}
\begin{equation} x \end{equation}
\subsubsection{z}
\begin{equation} x \end{equation}
\begin{equation} x \end{equation}
\clearpage
\section{Item II}
\clearpage
\subsection{Item IIa}
\clearpage
\subsubsection{A}
\subsubsubsection{x}
\begin{equation} x \end{equation}
\begin{equation} x \end{equation}
\subsubsubsection{y}
\begin{equation} x \end{equation}
\begin{equation} x \end{equation}
\subsubsubsection{z}
\begin{equation} x \end{equation}
\begin{equation} x \end{equation}
\clearpage
\subsubsection{B}
\subsubsubsection{x}
\begin{equation} x \end{equation}
\begin{equation} x \end{equation}
\subsubsubsection{y}
\begin{equation} x \end{equation}
\begin{equation} x \end{equation}
\subsubsubsection{z}
\begin{equation} x \end{equation}
\begin{equation} x \end{equation}
\clearpage
\subsubsection{C}
\subsubsubsection{x}
\subsubsubsection{y}
\subsubsubsection{z}
\clearpage
\subsection{Item IIb}
\clearpage
\subsubsection{A}
\subsubsubsection{x}
\begin{equation} x \end{equation}
\begin{equation} x \end{equation}
\subsubsubsection{y}
\begin{equation} x \end{equation}
\begin{equation} x \end{equation}
\subsubsubsection{z}
\begin{equation} x \end{equation}
\begin{equation} x \end{equation}
\clearpage
\subsubsection{B}
\subsubsubsection{x}
\begin{equation} x \end{equation}
\begin{equation} x \end{equation}
\subsubsubsection{y}
\begin{equation} x \end{equation}
\begin{equation} x \end{equation}
\subsubsubsection{z}
\begin{equation} x \end{equation}
\begin{equation} x \end{equation}
\clearpage
\subsubsection{C}
\subsubsubsection{x}
\subsubsubsection{y}
\subsubsubsection{z}
\clearpage
\section{Item IV}
\clearpage
\subsection{x}
\begin{equation} x \end{equation}
\begin{equation} x \end{equation}
\subsection{y}
\begin{equation} x \end{equation}
\begin{equation} x \end{equation}
\subsection{z}
\begin{equation} x \end{equation}
\begin{equation} x
\end{equation}
\end{document}
编辑:新版本
以下代码使用toggle
和命令\toggleformat
在两种格式之间切换,即\origtheequation
提供的标准格式和用户定义的格式,隐藏在名为的包装器命令中\myequationformat
。
重置也切换回标准section
级别。
\let\origtheequation\theequation
\newcommand{\formatsubstitute}[1]{%
\csname the#1\endcsname-\arabic{equation}%
}
\newtoggle{enableFormat}
\newcommand{\myequationformat}{%
\ifnum\value{subsection} > 0
\ifnum\value{subsubsection} > 0
\ifnum\value{paragraph} > 0
\ifnum\value{subparagraph} > 0
\formatsubstitute{subparagraph}
\else % it's paragraph
\formatsubstitute{paragraph}
\fi
\else % it's subsubsection
\textbf{\formatsubstitute{subsubsection}}
\fi
\else % it's subsection
\formatsubstitute{subsection}
\fi
\else % it's section
\textbf{\formatsubstitute{section}}
\fi
}
\newcommand{\toggleformat}{%
\iftoggle{enableFormat}{%
\counterwithin{equation}{section} % Reset with \subparagraph
\let\theequation\origtheequation%
\togglefalse{enableFormat}%
}{%
\counterwithin{equation}{subparagraph} % Reset with \subparagraph
\let\theequation\myequationformat%
\toggletrue{enableFormat}%
}%
}
以下是一段相当冗长的测试代码:
\documentclass{scrartcl}
\usepackage{geometry} % margin/page layout settings
\usepackage{scrlayer-scrpage} % improved header commands. [supercedes `fancyhdr' package].
\usepackage{mathtools} % includes amsmath, supplements it.
\usepackage{chngcntr} % allows changing equation section depth mid-document
\usepackage{etoolbox}
% Margin Settings:
\newlength{\xhmargin } \setlength{\xhmargin }{0.750in}
\newlength{\xtmargin } \setlength{\xtmargin }{0.750in}
\newlength{\xbmargin } \setlength{\xbmargin }{0.750in}
\newlength{\xheadheight} \setlength{\xheadheight}{2.700em}
\newlength{\xheadsep } \setlength{\xheadsep }{1.000em}
\newlength{\xfootheight} \setlength{\xfootheight}{2.700em}
\newlength{\xfootskip } \setlength{\xfootskip }{3.700em} % [ = Footheight + Footsep]
\KOMAoptions{fontsize = 12pt ,
parskip = half- ,
headheight = \xheadheight ,
footheight = \xfootheight ,
DIV = current }
\geometry{letterpaper ,
hmargin = \xhmargin ,
tmargin = \xtmargin ,
bmargin = \xbmargin ,
headsep = \xheadsep ,
footskip = \xfootskip }
%Initialize headers and footers
\chead{\normalfont Header 1 \\ Header 2}
\cfoot{\normalfont Footer 1 \\ Footer 2}
\ofoot{\normalfont Page \thepage}
\let\origtheequation\theequation
\newcommand{\formatsubstitute}[1]{%
\csname the#1\endcsname-\arabic{equation}%
}
\newtoggle{enableFormat}
\newcommand{\myequationformat}{%
\ifnum\value{subsection} > 0
\ifnum\value{subsubsection} > 0
\ifnum\value{paragraph} > 0
\ifnum\value{subparagraph} > 0
\formatsubstitute{subparagraph}
\else % it's paragraph
\formatsubstitute{paragraph}
\fi
\else % it's subsubsection
\textbf{\formatsubstitute{subsubsection}}
\fi
\else % it's subsection
\formatsubstitute{subsection}
\fi
\else % it's section
\textbf{\formatsubstitute{section}}
\fi
}
\newcommand{\toggleformat}{%
\iftoggle{enableFormat}{%
\counterwithin{equation}{section} % Reset with \subparagraph
\let\theequation\origtheequation%
\togglefalse{enableFormat}%
}{%
\counterwithin{equation}{subparagraph} % Reset with \subparagraph
\let\theequation\myequationformat%
\toggletrue{enableFormat}%
}%
}
% Section numbering: Table of contents and section depth
\setcounter{secnumdepth}{5}
% Section numbering: Format \paragraph like \subsection
\newcommand{\subsubsubsection} [1] { \paragraph{#1} }
\makeatletter
\renewcommand{\paragraph} %
{\@startsection{paragraph}{4}{\z@} %
{-2.5ex\@plus -1ex \@minus -.25ex} %
{1.25ex \@plus .25ex} %
{\normalfont\sffamily\normalsize\bfseries} }
\makeatother
\begin{document}
\section{Item 0}
\begin{equation}
x
\end{equation}
\begin{equation}
x
\end{equation}
\subsection{First sub}
\begin{equation}
x \label{first}
\end{equation}
\subsubsection{First subsub}
\begin{equation}
x \label{second}
\end{equation}
\subsubsubsection{First paragraph}
\begin{equation}
x \label{third}
\end{equation}
\subparagraph{First subparagraph}
\begin{equation}
x \label{fourth}
\end{equation}
\toggleformat
\section{Item I}
\begin{equation}
x
\end{equation}
\begin{equation}
x
\end{equation}
\subsection{First sub}
\begin{equation}
\end{equation}
\subsubsection{First subsub}
\begin{equation}
x
\end{equation}
\subsubsubsection{First paragraph}
\begin{equation}
x
\end{equation}
\subparagraph{First subparagraph}
\begin{equation}
x
\end{equation}
\clearpage
\subsection{A}
\subsubsection{x}
\begin{equation} x \end{equation}
\begin{equation} x \end{equation}
\subsubsection{y}
\begin{equation} x \end{equation}
\begin{equation} x \end{equation}
\subsubsection{z}
\begin{equation} x \end{equation}
\begin{equation} x \end{equation}
\clearpage
\subsection{B}
\subsubsection{x}
\begin{equation} x \end{equation}
\begin{equation} x \end{equation}
\subsubsection{y}
\begin{equation} x \end{equation}
\begin{equation} x \end{equation}
\subsubsection{z}
\begin{equation} x \end{equation}
\begin{equation} x \end{equation}
\clearpage
\section{Item II}
\begin{equation}
x \label{fifth}
\end{equation}
\clearpage
\subsection{Item IIa}
\clearpage
\subsubsection{A}
\subsubsubsection{x}
\begin{equation} x \end{equation}
\begin{equation} x \end{equation}
\subsubsubsection{y}
\begin{equation} x \end{equation}
\begin{equation} x \end{equation}
\subsubsubsection{z}
\begin{equation} x \end{equation}
\begin{equation} x \end{equation}
\clearpage
\subsubsection{B}
\subsubsubsection{x}
\begin{equation} x \end{equation}
\begin{equation} x \end{equation}
\subsubsubsection{y}
\begin{equation} x \end{equation}
\begin{equation} x \end{equation}
\subsubsubsection{z}
\begin{equation} x \end{equation}
\begin{equation} x \end{equation}
\clearpage
\subsubsection{C}
\subsubsubsection{x}
\subsubsubsection{y}
\subsubsubsection{z}
\clearpage
\subsection{Item IIb}
\clearpage
\subsubsection{A}
\subsubsubsection{x}
\begin{equation} x \end{equation}
\begin{equation} x \end{equation}
\subsubsubsection{y}
\begin{equation} x \end{equation}
\begin{equation} x \end{equation}
\subsubsubsection{z}
\begin{equation} x \end{equation}
\begin{equation} x \end{equation}
\clearpage
\subsubsection{B}
\subsubsubsection{x}
\begin{equation} x \end{equation}
\begin{equation} x \end{equation}
\subsubsubsection{y}
\begin{equation} x \end{equation}
\begin{equation} x \end{equation}
\subsubsubsection{z}
\begin{equation} x \end{equation}
\begin{equation} x \end{equation}
\clearpage
\subsubsection{C}
\subsubsubsection{x}
\subsubsubsection{y}
\subsubsubsection{z}
\clearpage
\toggleformat
\section{Item IV}
\clearpage
\subsection{x}
\begin{equation} x \end{equation}
\begin{equation} x \end{equation}
\subsection{y}
\begin{equation} x \end{equation}
\begin{equation} x \end{equation}
\subsection{z}
\begin{equation} x \end{equation}
\begin{equation} x \end{equation}
\end{document}