我正在為我的班級寫一些論文,並希望將任務編號為兩到三個級別。第一級應該是一個簡單的數字,如 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}