
我希望所有小節的名稱都相同,後面有一個數字。我想出的直接方法是這樣的:
\section{User Stories}
\subsection*{Userstory 1}
This is story 1
\subsection*{Userstory 2}
This is story 2
但我想這不可能作為一個清單嗎?所以我嘗試了一些方法但沒有成功。我剛剛學習了 LaTeX 的基礎知識,我想在 LateX 中嘗試一些更高級的技巧,但行不通。我已經嘗試過這個以及一些與此非常相似的事情:
\section{User Stories}
\begin{enumerate} [label=\subsection*{Userstory \arabic*}]
\item This is story 1
\item This is story 2
\end{enumerate}
這種行為甚至有可能自動發生嗎?最好的方法是什麼,不要每次都輸入號碼和標題。先致謝!
答案1
也許這就夠了。
\documentclass{article}
\newcounter{userstory}
\def\nextUserStory{\stepcounter{userstory}\subsection*{User Story \theuserstory}}
\begin{document}
\section{User Stories}
\nextUserStory
This is story 1
\nextUserStory
This is story 2
\end{document}
如果我理解菲奧娜的評論,她希望有一個選項來標記故事。編輯以反映egreg對Fiona相關問題的評論對「假」部分的交叉引用(參見「作為枚舉的小節」)。特別是,\refstepcounter
需要 來代替\stepcounter
,\label
不必是宏的一部分\nextUserStory
。
\documentclass{article}
\newcounter{userstory}
\newcommand\nextUserStory{\refstepcounter{userstory}\subsection*{User Story \theuserstory}}
\begin{document}
\section{User Stories}
\nextUserStory\label{storyA}
This is story 1
\nextUserStory
This is story 2, which refers to story \ref{storyA}.
\end{document}