82

I'm doing homework from a particular book, and each question is numbered after the page number and the question number. For example 52.2, 52.9, 53.13, etc. (Note that they are not sequential.)

How do I do something that will work like the enumerate environment, but instead of 1. 2. 3., etc. at each \item, I put a custom number?

0

6 Answers 6

117

You could simply use the optional Argument of \item

\documentclass{scrartcl}

\begin{document}
\begin{itemize}
    \item [2.9] Foo
    \item [53.2] Bar
    \item [69.11]
\end{itemize}
\end{document}

I hope that’s what you wanted to do …

10
  • 1
    Thanks. Strangely enough, I wasn't aware of the itemize function :O ... useful! Sep 29, 2011 at 0:43
  • 3
    That's what I usually do, but the alignment works the other way I expect it to and I often have to fix it by defining my own lists. Any other means to do it? Sep 29, 2011 at 1:12
  • 1
    @Francois: Please post a separate question with a MWE that shows the problem. Sep 29, 2011 at 1:31
  • 7
    You can also do this using the enumerate environment (that is, in this instance, itemize and enumerate can be interchanged). Also, from a terminology perspective, these are environments.
    – Werner
    Sep 29, 2011 at 1:40
  • 2
    @geo909: This is because the labels, which is “Question” in your case, have a fixed width. If you have such list {description} seems to be more appropriate. You can also increase the label width e.g. by using the enumitem package.
    – Tobi
    Jan 25, 2015 at 11:34
32

The genuinely insane way to do this is as follows:

\documentclass{article}
\usepackage{enumitem}
\makeatletter
\newcommand*{\wackyenum}[1]{%
  \expandafter\@wackyenum\csname c@#1\endcsname%
}

\newcommand*{\@wackyenum}[1]{%
  $\ifcase#1\or52.2\or52.9\or53.13\or42%
    \else\@ctrerr\fi$%
}
\AddEnumerateCounter{\wackyenum}{\@wackyenum}{53.13}
\makeatother


\begin{document}
\begin{enumerate}[label=\wackyenum*]
\item One
\item Two
\item Three
\end{enumerate}
\end{document}

This allows you to define an arbitrary list of numbers that the the enumeration will cycle through. This has the (very minor) advantage of having the spacing behave a little better. This is basically how a lot of things are done in the moreenum package. The documentation explains the procedure.

0
18

Depending on how much "non-sequential" your numbers are, and how much you need a quick & dirty solution instead of something with polish and automatism, you might get along with \addtocounter and some ad-hoc-ery involving the enumitem package:

\documentclass{article}

\usepackage{enumitem}

\begin{document}

\begin{enumerate}[label=52.\arabic*,start=2]
\item Answer % 52.2
\addtocounter{enumi}{6}
\item Answer % 52.9
\end{enumerate}

\begin{enumerate}[label=53.\arabic*,start=13]
\item Answer % 53.13
\end{enumerate}

\end{document}

With a bit more work, you could make the page number (52, 53) into a counter of its own and wrap it all into a re-useable environment definition, but I think this gives you the idea of it all.

6

Building up on Seamus's insane answer, here is how to do the same in ConTeXt.

\defineconversion[insane][52.2, 52.9, 53.13,42]

\starttext
\startitemize[insane]
  \item One
  \item Two
  \item Three
\stopitemize
\stoptext
4

To get automatically the page number you can do as follows

\documentclass[a4paper]{article}
\usepackage{enumitem,refcount}
\newcounter{qcount}
\newenvironment{questions}
  {\refstepcounter{qcount}\label{qcount\theqcount}%
   \begin{itemize}[label=\protect\getpagerefnumber{qcount\theqcount}.\protect\qcountnum]}
  {\end{itemize}}
\newcommand{\qitem}[1]{\def\qcountnum{#1}\item}

\begin{document}

\begin{questions}
\qitem{2} A
\qitem{25} B
\end{questions}

\newpage

\begin{questions}
\qitem{3} C
\qitem{7} D
\end{questions}

\end{document}

At each questions environment a new label is generated, so we can use it for numbering the questions. The \qitem command wants as argument the question number. Since the mechanism exploits the \label-\ref system, two runs of latex are needed.

3

In modification of egreg's solution you may use package perpages to have enumeration per page:

\documentclass{article}
\usepackage{perpage}
\MakePerPage{enumi}
\renewcommand*{\theenumi}{\theperpage.\arabic{enumi}}
\newcommand*{\nitem}[1][]{%
  \ifx\relax#1\relax\else\setcounter{enumi}{\numexpr #1-1\relax}\fi
  \item
}
\usepackage{lipsum}

\begin{document}

\makeatletter\@whilenum\value{page}<100\do{% demonstration of 99 pages
  \lipsum[\thepage]
  \begin{enumerate}
  \nitem A
  \nitem[7] B
  \nitem[19] C
  \nitem \lipsum[\thepage]
  \nitem D
  \end{enumerate}
  \newpage
}
\end{document}

Instead of redefining theenumi you may redefine \labelenumi:

\renewcommand*{\labelenumi}{\theperpage.\theenumi}

The difference is that \label/\ref will reference the number without page.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .