我正在为我的班级写一些论文,并希望将任务编号为两到三个级别。第一级应该是一个简单的数字,如 1),而下一级应该用数字标记。看看这个问题如何在页边空白处对段落(和章节)进行编号?它几乎回答了我的需求。我尝试自己更改编号,但遇到了一些困难。
正如您所看到的,第一个子段落被跳过并被替换为)。我不知道我的代码是否是最好的,如果有人有更好的方法来获得类似的输出,我将很高兴听到它。我发现将 \section 和 \subsection 级别与 \paragraph 级别混合在一起有点奇怪。
\documentclass[10pt,a4paper]{article}
\usepackage{amssymb,mathtools} % Matematikk.
\usepackage{enumitem} % Mer muligheter for lister
\usepackage{titlesec}
\usepackage{etoolbox}
\setcounter{secnumdepth}{5}
\renewcommand\thesection{\bfseries\small\arabic{section})}
% this length controls tha hanging indent for titles
% change the value according to your needs
\newlength\titleindent
\setlength\titleindent{1cm}
\pretocmd{\paragraph}{\stepcounter{subsection}}{}{}
\pretocmd{\subparagraph}{\stepcounter{subsubsection}}{}{}
\newcounter{problem}[section]
\setcounter{problem}{1}
\renewcommand{\theproblem}{\bfseries\small\alph{problem})}
\titleformat{\paragraph}[runin]
{\normalfont\large}{\llap{\parbox{\titleindent}{\thesection\hfill}}\stepcounter{section}}{0em}{}
\titleformat{\subparagraph}[runin]
{\normalfont\large}{\llap{\parbox{\titleindent}{\theproblem\hfill}}\stepcounter{problem}}{0em}{}
\titlespacing*{\paragraph}{0pt}{3.25ex plus 1ex minus .2ex}{0em}
\titlespacing*{\subparagraph}{0pt}{3.25ex plus 1ex minus .2ex}{0em}
\setcounter{section}{1}
\begin{document}
\paragraph{}
Given an element $x$, $x_v$ is its value and $x_s$ its unit.
Let the set $D$ be a standard deck of $52$ cards.
\subparagraph{}
Find the cardinality of the following sets:
\begin{enumerate}[leftmargin=*]
\item $S = \left\{ x \in D \mid x_s = \text{spades} \right\}$
\item $B = \left\{ \text{the set of court cards in } D \right\}$
\item $S \cap B$
\item $S \cup B$
\item $S\,\backslash\,B$
\item $S \times B$
\item $\left\{ (x,y) \in D \times D \mid x = y \right\}$
\end{enumerate}
\subparagraph{}
Fill in the correct symbol $\in,\,\subseteq\,\, \nsubseteq$
\begin{enumerate}[leftmargin=*]
\item ace of hearts
\item ace of hearts
\item S D
\item S B
\end{enumerate}
\subparagraph{Fee fuu foo}
\end{document}
答案1
我真的不明白为什么使用section
段落计数器、subsection
小段落计数器和新计数器problem
;这里有一个变体,其中每个部分单元都使用其自然计数器,而不需要额外的计数器:
\documentclass[10pt,a4paper]{article}
\usepackage{amssymb,mathtools}
\usepackage{enumitem}
\usepackage{titlesec}
\setcounter{secnumdepth}{5}
% this length controls tha hanging indent for titles
% change the value according to your needs
\newlength\titleindent
\setlength\titleindent{1cm}
\renewcommand\theparagraph{\bfseries\small\arabic{paragraph})}
\renewcommand\thesubparagraph{\bfseries\small\alph{subparagraph})}
\titleformat{\paragraph}[runin]
{\normalfont\large}{\llap{\parbox{\titleindent}{\theparagraph\hfill}}}{0em}{}
\titleformat{\subparagraph}[runin]
{\normalfont\large}{\llap{\parbox{\titleindent}{\thesubparagraph\hfill}}}{0em}{}
\titlespacing*{\paragraph}{0pt}{3.25ex plus 1ex minus .2ex}{0em}
\titlespacing*{\subparagraph}{0pt}{3.25ex plus 1ex minus .2ex}{0em}
\setlist[enumerate]{leftmargin=*}
\begin{document}
\paragraph{}
Given an element $x$, $x_v$ is its value and $x_s$ its unit.
Let the set $D$ be a standard deck of $52$ cards.
\subparagraph{}
Find the cardinality of the following sets:
\begin{enumerate}
\item $S = \left\{ x \in D \mid x_s = \text{spades} \right\}$
\item $B = \left\{ \text{the set of court cards in } D \right\}$
\item $S \cap B$
\item $S \cup B$
\item $S\,\backslash\,B$
\item $S \times B$
\item $\left\{ (x,y) \in D \times D \mid x = y \right\}$
\end{enumerate}
\subparagraph{}
Fill in the correct symbol $\in,\,\subseteq\,\, \nsubseteq$
\begin{enumerate}
\item ace of hearts
\item ace of hearts
\item S D
\item S B
\end{enumerate}
\subparagraph{Fee fuu foo}
\end{document}
如果您不打算使用分段单位的参数,那么使用分段单位仅实现编号似乎“不自然”;这是您的代码的新变体,它不使用分段单位,而是使用使用该enumitem
包定义的新列表式环境:
\documentclass[10pt,a4paper]{article}
\usepackage{amssymb,mathtools}
\usepackage{enumitem}
\usepackage{titlesec}
\newlength\titleindent
\setlength\titleindent{1cm}
\newlist{problem}{enumerate}{3}
\setlist[problem,1]{label=\textbf{\arabic*)},leftmargin=0pt,labelsep=\titleindent,itemsep=3.25ex}
\setlist[problem,2]{label=\textbf{\alph*)},leftmargin=0pt,labelsep=\titleindent,itemindent=-7pt,itemsep=3.25ex}
\setlist[problem,3]{label=\arabic*.,leftmargin=\dimexpr\titleindent-20pt\relax,labelsep=10pt}
\begin{document}
\begin{problem}
\item Given an element $x$, $x_v$ is its value and $x_s$ its unit.
Let the set $D$ be a standard deck of $52$ cards.
\begin{problem}
\item Find the cardinality of the following sets:
\begin{problem}
\item $S = \left\{ x \in D \mid x_s = \text{spades} \right\}$
\item $B = \left\{ \text{the set of court cards in } D \right\}$
\item $S \cap B$
\item $S \cup B$
\item $S\,\backslash\,B$
\item $S \times B$
\item $\left\{ (x,y) \in D \times D \mid x = y \right\}$
\end{problem}
\item Fill in the correct symbol $\in,\,\subseteq\,\, \nsubseteq$
\begin{problem}
\item ace of hearts
\item ace of hearts
\item S D
\item S B
\end{problem}
\item Fee fuu foo
\end{problem}
\end{problem}
\end{document}