Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I want to have subsections named all the same with a number behind it. The straight forward approach I came up with is this:

\section{User Stories}
\subsection*{Userstory 1}
This is story 1
\subsection*{Userstory 2}
This is story 2

But I though isn't this possible as a list? So I have tried a few things but none worked. I have just learned the basics of LaTeX, and I want to try some more advanced tricks in LateX, but it won't work. I have tried this and some things very similar to this:

\section{User Stories}
\begin{enumerate} [label=\subsection*{Userstory \arabic*}]
    \item This is story 1
    \item This is story 2
\end{enumerate}

Is this behaviour even possible to automatically? What is the best approach, for not typing the number and the title every time. Thanks in advance!

share|improve this question
    
I almost asked this question yesterday but I couldn't think how to phrase it - so thanks martijnn –  FionaSmith May 9 at 13:41

1 Answer 1

up vote 5 down vote accepted

Perhaps this would suffice.

\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}

enter image description here


If I understand Fiona's comment, she would like to have an option to label stories. EDITED to reflect egreg's comment at Fiona's related question Cross references to "false" sections (see "subsections as an enumerate"). In particular, \refstepcounter is needed in lieu of \stepcounter, and the \label need not be part of the \nextUserStory macro.

\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}

enter image description here

share|improve this answer
    
This is exactly what I am looking for :) I have added \setcounter{userstory}{0} right after the \section{User Stories} just to be sure that the counter is 1. –  martijnn2008 May 9 at 12:42
    
@martijnn2008 I didn't set because the counter would be initialized to zero at the start anyway. However, if this is used in multiple sections, the counter would indeed need to be reset to zero for each section where used. –  Steven B. Segletes May 9 at 12:47
    
See my edit. :) But I got the point thank you. –  martijnn2008 May 9 at 12:47
    
@martijnn2008 See mine. :^) –  Steven B. Segletes May 9 at 12:48
    
@StevenB.Segletes if you're still online - what happens when you want to add a \cref to such sections? This also happens to be exactly what I want to do but I would like to be able to refer to them elsewhere in the text. –  FionaSmith May 9 at 13:39

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.