\@startsection 没有遵循深度?

\@startsection 没有遵循深度?

键入时:

\newcommand\subsectionNotIndented{%
  \@startsection{subsectionNotIndented}{3}
  {\z@}% Left indentation
  {2mm plus 1mm minus 1mm}% Space above
  {2mm plus 1mm minus 1mm}% space after label
  {\normalfont\large\bfseries\color{color1}}% font for
}

我期望该部分深度为 3,即看起来像目录中的子部分。但事实并非如此,它不仅出现在顶层,而且还弄乱了所有剩余的目录条目:

在此处输入图片描述

我究竟做错了什么?

平均能量损失

\documentclass[11pt,a4paper,colorlinks]{moderncv}
\moderncvtheme[blue]{classic}
\firstname{Foo}
\familyname{bar}
\title{My title}
\address{Adress}

\makeatletter
\newcounter{subsectionNotIndented}
\newcommand\subsectionNotIndented{%
  \@startsection{subsectionNotIndented}{3}
  {\z@}% Left indentation
  {2mm plus 1mm minus 1mm}% Space above
  {2mm plus 1mm minus 1mm}% space after label
  {\normalfont\large\bfseries\color{color1}}% font for
}
\newcounter{subsubsectionNotIndented}
\newcommand\subsubsectionNotIndented{%
  \@startsection{subsubsectionNotIndented}{4}
  {0mm}% Left indentation
  {1mm plus .5mm minus .5mm}% Space above
  {1mm plus .5mm minus .5mm}% space after label
  {\normalfont\normalsize\color{color1}}% font for
}
\newcommand\subsectionNotIndentedmark[1]{}
\newcommand\subsubsectionNotIndentedmark[1]{}
\makeatother


\begin{document}
\pagestyle{empty}
\maketitle

\section{Foo}
\subsection{Bar}
\subsection{Baz}

\section{Fooo}
\subsection{Baar}
\subsection{Baaz}

\section{MyFoo}
\subsectionNotIndented{MyBarr}
\subsubsectionNotIndented{MySubBarr}
\subsubsectionNotIndented{MySubBarrr}

\subsectionNotIndented{MyBazz}
\subsubsectionNotIndented{MySuubBarr}
\subsubsectionNotIndented{MySuubBarrr}

\section{Foooo}
\subsection{Babar}
\subsection{Babaz}

\end{document}

答案1

感谢 Ulrike 的评论(抱歉,我习惯于调试与 LaTeX 编程相关的东西,而不是 LaTeX 格式化的东西……我甚至没有想到日志可能会有帮助),我意识到终端正在发出警告Warning: bookmark level for unknown subsectionNotIndented defaults to 0.。经过一番谷歌搜索,我很快成立解决方案:我需要添加\@namedef{toclevel@subsectionNotIndented}{2}

\documentclass[11pt,a4paper,colorlinks]{moderncv}
\moderncvtheme[blue]{classic}
\firstname{Foo}
\familyname{bar}
\title{My title}
\address{Adress}

\makeatletter
\newcounter{subsectionNotIndented}
\@namedef{toclevel@subsectionNotIndented}{2}
\newcommand\subsectionNotIndented{%
  \@startsection{subsectionNotIndented}{2}
  {\z@}% Left indentation
  {2mm plus 1mm minus 1mm}% Space above
  {2mm plus 1mm minus 1mm}% space after label
  {\normalfont\large\bfseries\color{color1}}% font for
}
\@namedef{toclevel@subsubsectionNotIndented}{3}
\newcounter{subsubsectionNotIndented}
\newcommand\subsubsectionNotIndented{%
  \@startsection{subsubsectionNotIndented}{3}
  {0mm}% Left indentation
  {1mm plus .5mm minus .5mm}% Space above
  {1mm plus .5mm minus .5mm}% space after label
  {\normalfont\normalsize\color{color1}}% font for
}
\newcommand\subsectionNotIndentedmark[1]{}
\newcommand\subsubsectionNotIndentedmark[1]{}
\makeatother


\begin{document}
\pagestyle{empty}
\maketitle

\section{Foo}
\subsection{Bar}
\subsection{Baz}

\section{Fooo}
\subsection{Baar}
\subsection{Baaz}

\section{MyFoo}
\subsectionNotIndented{MyBarr}
\subsubsectionNotIndented{MySubBarr}
\subsubsectionNotIndented{MySubBarrr}

\subsectionNotIndented{MyBazz}
\subsubsectionNotIndented{MySuubBarr}
\subsubsectionNotIndented{MySuubBarrr}

\section{Foooo}
\subsection{Babar}
\subsection{Babaz}

\end{document}

相关内容