对小节和小节进行编号,但不对章节进行编号

对小节和小节进行编号,但不对章节进行编号

我正在写一篇文章,但我不想为章节编号。但是,我希望为小节和小小节编号。现在我的文档有这个编号,但 0.XY 中的 0 不应该在那里。我该如何解决这个问题?

Currently:
Section
0.1 subsection
0.2 subsection
0.2.1 subsubsection
0.3 subsection

Should be:
Section
1. subsection
2. subsection
2.1 subsubsection
3. subsection

这是我的代码:

\documentclass{article}

\begin{document}

\section*{Section}

\subsection{subsection}

\subsection{subsection}

\subsubsection{subsubsection}
blah
\subsection{subsection}

\end{document}

附言:我做过在网上搜索,发现很多关于这个主题的内容,但没有针对这个特定问题的解决方案。

答案1

如果您希望\section{<heading>}以类似的方式打印\section*{<heading>}(即左对齐而不是缩进),那么titlesec提供一个简单的界面:

在此处输入图片描述

\documentclass{article}
\usepackage{titlesec}% http://ctan.org/pkg/titlesec
\titleformat{\section}%
  [hang]% <shape>
  {\normalfont\bfseries\Large}% <format>
  {}% <label>
  {0pt}% <sep>
  {}% <before code>
\renewcommand{\thesection}{}% Remove section references...
\renewcommand{\thesubsection}{\arabic{subsection}}%... from subsections
\begin{document}

\section{First section}
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam sollicitudin rutrum tellus, 
eu luctus dolor commodo eu. Integer pellentesque mollis congue.

\subsection{First subsection}
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam sollicitudin rutrum tellus, 
eu luctus dolor commodo eu. Integer pellentesque mollis congue.

\subsection{Second subsection}
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam sollicitudin rutrum tellus, 
eu luctus dolor commodo eu. Integer pellentesque mollis congue.

\subsubsection{First subsubsection}
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam sollicitudin rutrum tellus, 
eu luctus dolor commodo eu. Integer pellentesque mollis congue.

\subsection{Last subsection}
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam sollicitudin rutrum tellus, 
eu luctus dolor commodo eu. Integer pellentesque mollis congue.

\section{Second section}
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam sollicitudin rutrum tellus, 
eu luctus dolor commodo eu. Integer pellentesque mollis congue.

\subsection{First subsection}
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam sollicitudin rutrum tellus, 
eu luctus dolor commodo eu. Integer pellentesque mollis congue.

\end{document}​

这只是将节号和标题之间的标签分隔符设置为0pt,并且不打印数字。\normalfont\bfseries\Large是默认格式article

答案2

注意:在了解到 Ulrike Fisher 对@knut 的回答的评论后,我对这个答案进行了大量重写。

需要采取两个步骤。第一步,简单直接,就是重新定义宏\thesubsection。第二步,不太明显的步骤,涉及重新定义 LaTeX 内部宏\@seccntformat,如书中所述LaTeX 伴侣,第 2 版。以下 MWE 应用这两个步骤:

在此处输入图片描述

\documentclass{article}

\renewcommand{\thesubsection}{\arabic{subsection}}
\makeatletter
\def\@seccntformat#1{\@ifundefined{#1@cntformat}%
   {\csname the#1\endcsname\quad}%    default
   {\csname #1@cntformat\endcsname}}% enable individual control
\newcommand\section@cntformat{}     % section level 
\makeatother

\begin{document}
\section{First Section}
\subsection{First subsection}
\subsection{Second subsection}
\subsubsection{First subsubsection}
\subsection{Third subsection}
\section{Second Section}
\subsection{A new subsection}
\end{document}

附录解决@Adam 的后续问题:要(a)在章节标题中的小节(和子小节)数字后添加点和(b)用替换隐式\quad间距指令\space,您需要在序言中紧接着提供以下两个指令\makeatother

\newcommand\subsection@cntformat{\thesubsection.\space}
\newcommand\subsubsection@cntformat{\thesubsubsection.\space}

修订后的 MWE:

在此处输入图片描述

\documentclass{article}

\renewcommand{\thesubsection}{\arabic{subsection}}
\makeatletter
\def\@seccntformat#1{\@ifundefined{#1@cntformat}%
   {\csname the#1\endcsname\quad}%    default
   {\csname #1@cntformat\endcsname}}% enable individual control
\newcommand\section@cntformat{}     % section level 
\newcommand\subsection@cntformat{\thesubsection.\space} % subsection level
\newcommand\subsubsection@cntformat{\thesubsubsection.\space} % subsubsection level
\makeatother

\begin{document}
\section{First Section}
\subsection{First subsection}
\subsection{Second subsection}
\subsubsection{First subsubsection}
\subsection{Third subsection}
\section{Second Section}
\subsection{A new subsection}
\end{document}

答案3

这对你有用吗:

\documentclass{article}

\begin{document}

\part*{Section}

\section{subsection}

\section{subsection}

\subsection{subsubsection}
blah
\section{subsection}

\end{document}

或者是否存在特殊原因,为什么需要将节作为节,将子节作为子节?


选择:

\documentclass{article}

\renewcommand{\thesection}{}
\renewcommand{\thesubsection}{\arabic{subsection}}

\begin{document}

\section{Section}

\subsection{subsection}

\subsection{subsection}

\subsubsection{subsubsection}
blah
\subsection{subsection}

\section{Section 2}

\subsection{subsection 2}
This subsection starts again with 1.


\end{document}

相关内容