有没有简单的方法可以在标题中显示章节编号?我目前正在使用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
另一个级别。
\pdfstrcmp
pdftex
是和提供的原语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}