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'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?

share|improve this question

6 Answers 6

up vote 33 down vote accepted

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 …

share|improve this answer
    
Thanks. Strangely enough, I wasn't aware of the itemize function :O ... useful! –  iDontKnowBetter Sep 29 '11 at 0:43
1  
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? –  François G. Dorais Sep 29 '11 at 1:12
1  
@Francois: Please post a separate question with a MWE that shows the problem. –  Peter Grill Sep 29 '11 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 '11 at 1:40

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.

share|improve this answer
6  
+1 for the phrase "genuinely insane". –  N.N. Sep 29 '11 at 12:14

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.

share|improve this answer

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
share|improve this answer

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.

share|improve this answer

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.

share|improve this answer

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.