我以为我已经解决了这个问题过去,
但我无法让它工作。
我想要的是:
我正在寻求一个解决方案:
A.1.3 — 10
在所有浮动计数器
以及作者希望使用的任何其他计数器中排版完整的章节编号(例如:) 。提供自动选择当前截面深度的选项。
允许作者在序言和文档中设置选项。
如果选项已经设置,则允许作者在文档中间更改选项。
我得到了什么:
\renewcommand
序言中的“未重置计数器语法”,这
从equation
计数器编号中可以看出。
还:
除此之外,我不相信它能\determineSection
按预期工作。
我相信它提供了一个计数器值,而不是编码名称\thesection
等。
如何使用 if 开关输出\determineSection
如下代码:
subsubsection
\thesubsection
和有什么关系吗csname
?
平均能量损失
子文件/序言.tex:
% meta tools
\usepackage{etoolbox} % allows if/else statements in code. [required for: standalone+nocite fix, equation numbering.]
% math
\usepackage{mathtools} % includes amsmath, supplements it.
% font
\usepackage{listings} % improved version of verbatim. imports script languages (with syntax coloring).
\usepackage{color} % color commands.
\usepackage[dvipsnames]{xcolor} % additional color commands.
% layout: page/spacing/headings
\usepackage{appendix} % appendices.
\usepackage{scrlayer-scrpage} % improved header commands. [supercedes `fancyhdr' package].
% references
\usepackage{tocloft} % allows generation of list of equations. (used in MWE only.)
\usepackage{chngcntr} % allows changes mid-document to section depth of equation counter reset.
% floats: figures/tables/lists
% Sectioned Counters:
% Save a copy of the original float counters.
\let\xtheequationOriginal\theequation
\let\xthefigureOriginal\thefigure
\let\xthetableOriginal\thetable
\let\xthelstlistingOriginal\thelstlisting
% Create blank commands which will later act as variable rich-format counters.
\newcommand{\sectionedEquation}{.}
\newcommand{\sectionedFigure }{.}
\newcommand{\sectionedTable }{.}
\newcommand{\sectionedListing }{.}
% Set the float counters to the rich-format counter commands.
\let\theequation\sectionedEquation
\let\thefigure\sectionedFigure
\let\thetable\sectionedTable
\let\thelstlisting\sectionedListing
% Command: Determine Section
\newcommand{\determineSection}{% [Provides full section counter of current section, independent of the section depth.]
\ifnum\value{subsubsection} > 0
\ifnum\value{paragraph} > 0
\ifnum\value{subparagraph} > 0 \theparagraph
\else \thesubsubsection \fi
\else \thesubsection \fi
\else \thesection \fi
}
% Command: Sectioned Counter
\newcommand{\sectionedCounterStyle}[2]{#2--\arabic{#1}} % Input #1: equation, lstlisting, table, figure
% Input #2: \determineSection, \thesection, \thesubsection, ..
\newcommand{\sectionedCounter} [2] % Input #1: \determineSection, \thesection, \thesubsection, ..
{ % Input #2: section, section, subsection, ..
\counterwithin*{equation} {#2} % Reset counter whenever there is a new \section
\counterwithin*{figure} {#2}
\counterwithin*{table} {#2}
\counterwithin*{lstlisting}{#2} % The listings counter is not actually defined until \AtBeginDocument.
% Thus, if using this command (including listings) within the preamble,
% use ``\AtBeginDocument{\sectionedCounter{<input>}}'' instead.
\renewcommand{\sectionedEquation}{\sectionedCounterStyle{equation} {#1}}
\renewcommand{\sectionedFigure }{\sectionedCounterStyle{figure} {#1}}
\renewcommand{\sectionedTable }{\sectionedCounterStyle{table} {#1}}
\renewcommand{\sectionedListing }{\sectionedCounterStyle{lstlisting}{#1}}
}
% Set float counters to include their full section number.
\AtBeginDocument{\sectionedCounter{\thesubsection}{subsection}}
% -\determineSection is chosen by default as a catch-all, such that
% float counters adapt to any section level when running standalone subfiles
% which do not contain a \sectionedCounter command.
% It is assumed that in most cases, the author will set the counter depth to a specific level.
% Settings for importing scripts [listings package]
\lstset{frame = single}
% Settings for creating Lists of Equations
\newcommand{\listnameEquations}{List of Equations}
\newlistof{equations}{equ}{\listnameEquations}
\newcommand{\eqRef}[1]{%
\addcontentsline{equ}{equations}{\protect\numberline{\theequation}#1}\par}
主文件.tex:
%! arara: lmkclean
%! arara: pdflatex: { draft: yes }
%! arara: bibtex
% arara: pdflatex: { draft: yes }
% arara: pdflatex: { synctex: yes }
% arara: lmkclean
\documentclass[crop=false,float=true,class=scrartcl]{standalone}
\providecommand{\main}{.}
\input{\main/Subfiles/Preamble.tex} % Preamble [document configuration]
\begin{document}
\addcontentsline{toc}{section}{List of Contents} \tableofcontents \clearpage
\addtocontents {toc}{\string\vspace{-1em}}
\addcontentsline{toc}{section}{List of Equations} \listofequations \clearpage
\addtocontents {toc}{\string\vspace{-1em}}
\addcontentsline{toc}{section}{List of Code Listings} \lstlistoflistings \clearpage
\begin{equation} \mathrm{Equation\ null.1} \label{eq:null.1} \end{equation} \eqRef{Equation null.1}
\lstinputlisting[caption=script.m]{\main/Scripts/script.m}
\clearpage
\begin{equation} \mathrm{Equation\ null.2} \label{eq:null.2} \end{equation} \eqRef{Equation null.2}
\lstinputlisting[caption=script.m]{\main/Scripts/script.m}
\clearpage
\addtocontents {equ}{\string\vspace{+1em}}
\section{Section 1} \clearpage
\begin{equation} \mathrm{Equation\ 1.0.1} \label{eq:1.0.1} \end{equation} \eqRef{Equation 1.0.1}
\lstinputlisting[caption=script.m]{\main/Scripts/script.m}
\clearpage
\begin{equation} \mathrm{Equation\ 1.0.2} \label{eq:1.0.2} \end{equation} \eqRef{Equation 1.0.2}
\lstinputlisting[caption=script.m]{\main/Scripts/script.m}
\clearpage
\subsection{Subsection 1.1} \clearpage
\begin{equation} \mathrm{Equation\ 1.1.1} \label{eq:1.1.1} \end{equation} \eqRef{Equation 1.1.1}
\lstinputlisting[caption=script.m]{\main/Scripts/script.m}
\clearpage
\begin{equation} \mathrm{Equation\ 1.1.2} \label{eq:1.1.2} \end{equation} \eqRef{Equation 1.1.2}
\lstinputlisting[caption=script.m]{\main/Scripts/script.m}
\clearpage
\subsection{Subsection 1.2} \clearpage
\begin{equation} \mathrm{Equation\ 1.2.1} \label{eq:1.2.1} \end{equation} \eqRef{Equation 1.2.1}
\lstinputlisting[caption=script.m]{\main/Scripts/script.m}
\clearpage
\begin{equation} \mathrm{Equation\ 1.2.2} \label{eq:1.2.2} \end{equation} \eqRef{Equation 1.2.2}
\lstinputlisting[caption=script.m]{\main/Scripts/script.m}
\clearpage
\addtocontents {equ}{\string\vspace{+1em}}
\section{Section 2} \clearpage
\begin{equation} \mathrm{Equation\ 2.0.1} \label{eq:2.0.1} \end{equation} \eqRef{Equation 2.0.1}
\lstinputlisting[caption=script.m]{\main/Scripts/script.m}
\clearpage
\begin{equation} \mathrm{Equation\ 2.0.2} \label{eq:2.0.2} \end{equation} \eqRef{Equation 2.0.2}
\lstinputlisting[caption=script.m]{\main/Scripts/script.m}
\clearpage
\subsection{Subsection 2.1} \clearpage
\begin{equation} \mathrm{Equation\ 2.1.1} \label{eq:2.1.1} \end{equation} \eqRef{Equation 2.1.1}
\lstinputlisting[caption=script.m]{\main/Scripts/script.m}
\clearpage
\begin{equation} \mathrm{Equation\ 2.1.2} \label{eq:2.1.2} \end{equation} \eqRef{Equation 2.1.2}
\lstinputlisting[caption=script.m]{\main/Scripts/script.m}
\clearpage
\subsection{Subsection 2.2} \clearpage
\begin{equation} \mathrm{Equation\ 2.2.1} \label{eq:2.2.1} \end{equation} \eqRef{Equation 2.2.1}
\lstinputlisting[caption=script.m]{\main/Scripts/script.m}
\clearpage
\begin{equation} \mathrm{Equation\ 2.2.2} \label{eq:2.2.2} \end{equation} \eqRef{Equation 2.2.2}
\lstinputlisting[caption=script.m]{\main/Scripts/script.m}
\clearpage
\addtocontents {equ}{\string\vspace{+1em}}
\textbf{\LARGE{Appendices}}
\addappheadtotoc
\begin{appendices}
\section{Section A} \clearpage
\begin{equation} \mathrm{Equation\ A.0.1} \label{eq:A.0.1} \end{equation} \eqRef{Equation A.0.1}
\lstinputlisting[caption=script.m]{\main/Scripts/script.m}
\clearpage
\begin{equation} \mathrm{Equation\ A.0.2} \label{eq:A.0.2} \end{equation} \eqRef{Equation A.0.1}
\lstinputlisting[caption=script.m]{\main/Scripts/script.m}
\clearpage
\subsection{Subsection A.1} \clearpage
\begin{equation} \mathrm{Equation\ A.1.1} \label{eq:A.1.1} \end{equation} \eqRef{Equation A.1.1}
\lstinputlisting[caption=script.m]{\main/Scripts/script.m}
\clearpage
\begin{equation} \mathrm{Equation\ A.1.2} \label{eq:A.1.2} \end{equation} \eqRef{Equation A.1.2}
\lstinputlisting[caption=script.m]{\main/Scripts/script.m}
\clearpage
\subsection{Subsection A.2} \clearpage
\begin{equation} \mathrm{Equation\ A.2.1} \label{eq:A.2.1} \end{equation} \eqRef{Equation A.2.1}
\lstinputlisting[caption=script.m]{\main/Scripts/script.m}
\clearpage
\begin{equation} \mathrm{Equation\ A.2.2} \label{eq:A.2.2} \end{equation} \eqRef{Equation A.2.2}
\lstinputlisting[caption=script.m]{\main/Scripts/script.m}
\clearpage
\addtocontents {equ}{\string\vspace{+1em}}
\section{Section B} \clearpage
\begin{equation} \mathrm{Equation\ B.0.1} \label{eq:B.0.1} \end{equation} \eqRef{Equation B.0.1}
\lstinputlisting[caption=script.m]{\main/Scripts/script.m}
\clearpage
\begin{equation} \mathrm{Equation\ B.0.2} \label{eq:B.0.2} \end{equation} \eqRef{Equation B.0.2}
\lstinputlisting[caption=script.m]{\main/Scripts/script.m}
\clearpage
\subsection{Subsection 1.1} \clearpage
\begin{equation} \mathrm{Equation\ B.1.1} \label{eq:B.1.1} \end{equation} \eqRef{Equation B.1.1}
\lstinputlisting[caption=script.m]{\main/Scripts/script.m}
\clearpage
\begin{equation} \mathrm{Equation\ B.1.2} \label{eq:B.1.2} \end{equation} \eqRef{Equation B.1.2}
\lstinputlisting[caption=script.m]{\main/Scripts/script.m}
\clearpage
\subsection{Subsection 1.2} \clearpage
\begin{equation} \mathrm{Equation\ B.2.1} \label{eq:B.2.1} \end{equation} \eqRef{Equation B.2.1}
\lstinputlisting[caption=script.m]{\main/Scripts/script.m}
\clearpage
\begin{equation} \mathrm{Equation\ B.2.2} \label{eq:B.2.2} \end{equation} \eqRef{Equation B.2.2}
\lstinputlisting[caption=script.m]{\main/Scripts/script.m}
\clearpage
\end{appendices}
\end{document}
笔记:
使用\AtBeginDocument
列表计数器来自这里。
答案1
好吧,我不确定以前什么对我有用,或者为什么,但现在看来可以用它。
将以下代码放在序言中\sectionedCounter{<ctr>}
:这将提供在将章节编号插入浮动计数器时在序言中或文档中使用来设置章节深度的选项。
如果使用\sectionedCounter{\determineSection}
,则将使用最低级别的截面深度。
笔记:代码的最后几行启动命令。这不是必需的,但包含此代码是为了注意,当使用列表时,\AtBeginDocument{<cmd>}
在序言中使用命令时需要此代码。
% Sectioned Counters:
% Save a copy of the original float counters.
\let\xtheequationOriginal\theequation
\let\xthefigureOriginal\thefigure
\let\xthetableOriginal\thetable
\let\xthelstlistingOriginal\thelstlisting
% Create blank commands which will later act as variable rich-format counters.
\newcommand{\sectionedEquation}{\arabic{equation} }
\newcommand{\sectionedFigure }{\arabic{figure} }
\newcommand{\sectionedTable }{\arabic{table} }
\newcommand{\sectionedListing }{\arabic{lstlisting}}
% Set the float counters to the rich-format counter commands.
\let\theequation\sectionedEquation
\let\thefigure\sectionedFigure
\let\thetable\sectionedTable
\let\thelstlisting\sectionedListing
% Command: Determine Section
\newcommand{\determineSection}{% [Provides full section counter of current section, independent of the section depth.]
\ifnum\value{subsubsection} > 0
\ifnum\value{paragraph} > 0
\ifnum\value{subparagraph} > 0 paragraph%
\else subsubsection\fi
\else subsection\fi
\else section\fi
}
% Command: Sectioned Counter
\newcommand{\sectionedCounterStyle}[2]{\csname the#2\endcsname--\arabic{#1}}
% Input #1: equation, lstlisting, table, figure
% Input #2: \determineSection, \thesection, \thesubsection, ..
\newcommand{\sectionedCounter} [1]{
% Input #1: \determineSection, section, subsection, ..
\counterwithout*{equation} {section}
\counterwithout*{figure} {section}
\counterwithout*{table} {section}
\counterwithout*{lstlisting}{section}
\counterwithout*{equation} {subsection}
\counterwithout*{figure} {subsection}
\counterwithout*{table} {subsection}
\counterwithout*{lstlisting}{subsection}
\counterwithout*{equation} {subsubsection}
\counterwithout*{figure} {subsubsection}
\counterwithout*{table} {subsubsection}
\counterwithout*{lstlisting}{subsubsection}
\counterwithout*{equation} {paragraph}
\counterwithout*{figure} {paragraph}
\counterwithout*{table} {paragraph}
\counterwithout*{lstlisting}{paragraph}
\counterwithout*{equation} {subparagraph}
\counterwithout*{figure} {subparagraph}
\counterwithout*{table} {subparagraph}
\counterwithout*{lstlisting}{subparagraph}
\counterwithin{equation} {#1} % Reset counter whenever there is a new \section
\counterwithin{figure} {#1}
\counterwithin{table} {#1}
\counterwithin{lstlisting}{#1} % The listings counter is not actually defined until \AtBeginDocument.
% Thus, if using this command (including listings) within the preamble,
% use ``\AtBeginDocument{\sectionedCounter{<input>}}'' instead.
\renewcommand{\sectionedEquation}[1]{\sectionedCounterStyle{equation} {#1}}
\renewcommand{\sectionedFigure }[1]{\sectionedCounterStyle{figure} {#1}}
\renewcommand{\sectionedTable }[1]{\sectionedCounterStyle{table} {#1}}
\renewcommand{\sectionedListing }[1]{\sectionedCounterStyle{lstlisting}{#1}}
}
% Set float counters to include their full section number.
\AtBeginDocument{\sectionedCounter{\determineSection}}
% -\determineSection is chosen by default as a catch-all, such that
% float counters adapt to any section level when running standalone subfiles
% which do not contain a \sectionedCounter command.
% It is assumed that in most cases, the author will set the counter depth to a specific level.