我正在写一份报告,需要进行一些烦人的格式化。s\chapter
和\paragraph
s 需要使用阿拉伯数字进行编号。
在每个新章节开始时,需要重新设置段落编号。\section
、\subsection
和\subsubsection
标题不应编号,也不应对\paragraph
编号产生任何影响。
我不知道如何:
\paragraph
将每个 的开头编号重置为 1\chapter
。- 防止
\paragraph
在新开始时重置编号\subsubsection
。
考虑到我已经使用该titlesec
包来改变我的标题的外观,实现预期结果的最简单方法是什么?
\documentclass[a4paper,11pt,twoside]{report}
% Paragraph counter
\setcounter{secnumdepth}{5}
\renewcommand\theparagraph{\arabic{paragraph}}
\usepackage{graphicx,amssymb,amstext,amsmath,calc}
% Section headings
\usepackage[noindentafter,calcwidth]{titlesec}
\titleformat{\chapter}
[hang]
{\normalfont\uppercase}
{\bf{\thechapter.}}
{1em}
{\bfseries\filcenter}
[]
\titleformat{\section}
[hang]
{\normalfont\uppercase}
{}
{0pt}
{\bfseries}
[]
\titleformat{\subsection}
[hang]
{\normalfont}
{}
{0pt}
{\bfseries}
[]
\titleformat{\subsubsection}
[hang]
{\normalfont}
{}
{0pt}
{}
[{\titleline*[l]{\titlerule}}]
\titleformat{\paragraph}
[runin]
{\normalfont}
{\theparagraph.}
{1em}
{}
[]
\titlespacing*{\paragraph}
{0pc}
{11pt}
{11pt}
[]
\begin{document}
\chapter{First Chapter}
\paragraph{}First paragraph, numbered 1.
\section{First Section}
\paragraph{}Second paragraph, numbered 2.
\subsection{First Subsection}
\paragraph{}Third paragraph, numbered 3.
\subsubsection{First Subsubsection}
\paragraph{}Fourth paragraph, should be numbered 4.
\chapter{Second chapter, numbered 2.}
\paragraph{}This paragraph should be numbered 1.
\end{document}
答案1
这个chngcntr
包非常适合做这样的事情:
\usepackage{chngcntr}
\counterwithout{paragraph}{subsubsection} % removes paragraph from the subsubsections
\counterwithin{paragraph}{chapter} % makes paragraph depend on chapter
\renewcommand{\theparagraph}{\arabic{paragraph}} % redefine the display of the paragraph
答案2
艾伦·芒恩的解决方案可以通过使用星号版本进行改进\counterwithin*
——这样,paragraph
计数器将依赖于chapter
计数器没有改变 的定义\theparagraph
。
\usepackage{chngcntr}
\counterwithout{paragraph}{subsubsection}% makes paragraph independend from subsubsection;
% redefines \theparagraph as \arabic{paragraph}
\counterwithin*{paragraph}{chapter}% makes paragraph depend on chapter;
% does not change definition of \theparagraph