如何在章节标题中显示章节编号?

如何在章节标题中显示章节编号?

有没有简单的方法可以在标题中显示章节编号?我目前正在使用article文档类。

这是我的最小工作示例:

\documentclass[a4paper]{article}
\begin{document}

\section*{Introduction}

    Introduction text here...

\section{Item 1: What is Quantitative Finance?}
Indeed, before actually studying a topic, we should start by having a good definition of what we are studying. So what is quantitative finance?

\section{Item 2: Geometric Brownian Motion}
blalblabla

\end{document}

默认情况下,章节编号显示在章节标题前面。相反,我希望章节编号显示在文档标题内的“项目”一词后面,并自动递增(这样我就不需要手动计算项目编号了)。

答案1

你是指这样的吗?使用titlesec将自动使每个部分使用“Item xx”值。

\documentclass[a4paper]{article}
\usepackage{titlesec}
\titleformat{\section}[hang]{\bfseries}{Item \thesection:\ }{0pt}{}

\begin{document}

\section*{Introduction}

    Introduction text here...

\section{What is Quantitative Finance?}
Indeed, before actually studying a topic, we should start by having a good definition of what we are studying. So what is quantitative finance?

\section{Geometric Brownian Motion}
blalblabla

\end{document}

在此处输入图片描述

答案2

这里没有使用包,只是稍微重新定义\@seccntformat并检查\pdfstrcmp它是否是section另一个级别。

\pdfstrcmppdftex是和提供的原语pdflatex,因此它是一个内置命令。

\documentclass[a4paper]{article}


\makeatletter
\let\@seccntformatorig\@seccntformat
\def\@seccntformat#1{%
  \ifnum0=\pdfstrcmp{#1}{section}%
  Item \csname the#1\endcsname:{} %Well, could say Item \thesection:{} here as well... 
  \else
  \@seccntformatorig{#1}%
  \fi
}
\makeatother

\begin{document}




\section*{Introduction}

    Introduction text here...

\section{What is Quantitative Finance?}
Indeed, before actually studying a topic, we should start by having a good definition of what we are studying. So what is quantitative finance?

\subsection{Foo}


\section{Geometric Brownian Motion}
blalblabla

\end{document}

在此处输入图片描述

答案3

没有包,并且可能为不同的级别做不同的事情。在这里我定义\formatsection添加项目 n:\formatsubsection子项目 nm:,而标准输出用于\subsubsection

\documentclass[a4paper]{article}

\makeatletter
\renewcommand{\@seccntformat}[1]{%
  \ifcsname format#1\endcsname
    \csname format#1\endcsname
  \else
    \csname the#1\endcsname\quad
  \fi
}
\makeatother

\newcommand{\formatsection}{Item \thesection: }
\newcommand{\formatsubsection}{Subitem \thesubsection: } % just for example

\begin{document}

\section*{Introduction}

Introduction text here...

\section{What is Quantitative Finance?}

Indeed, before actually studying a topic, we should start by 
having a good definition of what we are studying. So what is 
quantitative finance?

\subsection{This is a subsection}

Here we have text.

\subsubsection{This is a subsubsection}

Here we have text.

\section{Geometric Brownian Motion}

blalblabla

\end{document}

在此处输入图片描述

相关内容