我使用包创建了新的部分(即“工作包”)和子部分(即“任务”)标题titlesec
。两个标题的定义如下。
% Workpackage section
\titleclass{\WP}{straight}[\section]
\titleformat{\WP}{\normalfont\normalsize\bfseries}{}{0em}{Work Package \theWP :\,}
\titlespacing*{\WP}{0pt}{2.25ex plus 1ex minus .2ex}{1.5ex plus .2ex}
\newcounter{WP}
\renewcommand\theWP{\arabic{WP}}
% Task subsection
\newcounter{Taskr}
\renewcommand\theTaskr{\theWP.\arabic{Taskr}}
\titleclass{\Taskr}{straight}[\WP]
\titleformat{\Taskr}[runin]{\normalfont\normalsize\itshape}{}{0em}{Task \theTaskr :\,}
\titlespacing*{\Taskr}{0pt}{2.25ex plus 1ex minus .2ex}{1.5ex plus .2ex}
\numberwithin{Taskr}{WP}
但是,当我编译该文档时,普通的小节标题没有标题编号,例如:
1. Section
Subsection
Subsection
2. Section
Subsection
Workpackage 1
Task 1.1
代替
1. Section
1.1 Subsection
1.2 Subsection
2. Section
2.2 Subsection
Workpackage 1
Task 1.1
如何修改我的定义?MWE 粘贴在下面。
\documentclass{article}
\usepackage{amsmath}
\usepackage{titlesec}
% Workpackage section
\titleclass{\WP}{straight}[\section]
\titleformat{\WP}{\normalfont\normalsize\bfseries}{}{0em}{Work Package \theWP :\,}
\titlespacing*{\WP}{0pt}{2.25ex plus 1ex minus .2ex}{1.5ex plus .2ex}
\newcounter{WP}
\renewcommand\theWP{\arabic{WP}}
% Task subsection
\newcounter{Taskr}
\renewcommand\theTaskr{\theWP.\arabic{Taskr}}
\titleclass{\Taskr}{straight}[\WP]
\titleformat{\Taskr}[runin]{\normalfont\normalsize\itshape}{}{0em}{Task \theTaskr :\,}
\titlespacing*{\Taskr}{0pt}{2.25ex plus 1ex minus .2ex}{1.5ex plus .2ex}
\numberwithin{Taskr}{WP}
% Don't want to include WP and Tasks into bookmarks and TOC
\makeatletter
\def\toclevel@WP{6}
\def\toclevel@Taskr{5}
\makeatother
\begin{document}
\section{Introduction}
\subsection{Problem definition}
\WP{Project management}
\Taskr{Project advisory board}
\end{document}
答案1
该\titleclass
命令被定义为插入一个新级别之间现有级别(将较低级别向下推),而不是现有级别的替代。然而,手动创建替代级别(没有titlesec
相关的编号行为)并不困难,您只需注意间距问题(注意:下面的示例无疑存在剩余问题)。
梅威瑟:
\documentclass{article}
\usepackage{amsmath}
%\usepackage{titlesec}
\newcounter{WP}
\newcounter{Taskr}
\newcommand{\WP}[1]{%
\stepcounter{WP}%
\setcounter{Taskr}{0}%
{\normalfont\normalsize\bfseries%
\bigbreak\noindent Work Package \theWP :\,#1}\par\noindent\ignorespaces%
}
\newcommand{\Taskr}[1]{%
\stepcounter{Taskr}%
{\normalfont\normalsize\itshape%
\par\noindent Task \theWP .\theTaskr :\,#1}\par\noindent\ignorespaces%
}
\begin{document}
\section{Introduction}
\subsection{Problem definition}
\WP{Project management}
This WP consists of two tasks.
\Taskr{Project advisory board}
Advise on the project.
\Taskr{Budget allocation}
\WP{Prototype}
\Taskr{Research existing solutions}
\subsection{Further considerations}
\end{document}
结果: