# Problems with paragraphs in margins

I am writing some papers for my class, and want to number the tasks with two or three levels. The first level should be a simple number like 1), while the next level should be labeled by numbers. Looking at this question How can I number paragraphs (and sections) in the margin? it almost answers what I need. I tried changing the numeration myself, but ran into some difficulties.

As one can see the first subparagraph is skipped and is replaced with a ). I do not know if my code is the best, and if anyone have a better way to obtain a similar output I would be glad to hear it. I find it a tad strange mixing \section and \subsection levels with the \paragraph ones.

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

I really don't understand why you use the section counter for paragraphs and the subsection counter for subparagraphs and a new counter problem; here's a variation in which each sectional unit uses its natural counter and no additional counters are needed:

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

If you are not going to use the arguments of the sectional units, it seems "unnatural" to use sectional units just to achieve numbering; here's a new variation of your code, without using sectional units but using instead a new list-like environment defined using the enumitem package:

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

-
Thanks a bunch =) When you are unexperienced it is easy to copy code, and not know what parts are wrong or superfluous, thanks again =) –  N3buchadnezzar Aug 22 '12 at 22:46
@N3buchadnezzar you're welcome! –  Gonzalo Medina Aug 22 '12 at 22:49
@N3buchadnezzar I've updated my answer with another approach not using the sectional unit commands (of course, this new approach is useful if you are not intending to effectively use the arguments of the sectional units). –  Gonzalo Medina Aug 23 '12 at 4:11
Sorry for bothering you, but is it possible to be able to use custom numbers for the \paragraphs? –  N3buchadnezzar Aug 23 '12 at 10:11
@N3buchadnezzar sure. You can redefine \theparagraph; what kind of representation for the paragraph counter would you like to have? –  Gonzalo Medina Aug 23 '12 at 12:11