[Lowerbounds, Upperbounds]

Algorithms are everywhere.

Another common task that seems to involve too much work in LaTeX is the customization of the enumerate environment. For example, you may want to have an enumerated list with labels Q-1, Q-2 and so on for listing questions.

The standard solution is not that hard:

\documentclass{article}
\begin{document}

\renewcommand{\theenumi}{\arabic{enumi}} % present the counter in arabic
\renewcommand{\labelenumi}{Q-\theenumi} % actual label
\makeatletter
\renewcommand{\p@enumi}{Q-} % change reference prefix
\makeatother

\begin{enumerate}
\item\label{hello} hello
\item\label{world} world
\end{enumerate}
Answer either \ref{hello} and \ref{world}.

\end{document}

But you may also consider using the enumerate package to do this:

\documentclass{article}
\usepackage{enumerate}
\begin{document}

\begin{enumerate}[Q-1]
\item\label{hello} hello
\item\label{world} world
\end{enumerate}
Answer either Q-\ref{hello} and Q-\ref{world}. % note the prefix

\end{document}

While it seems that the second example using enumerate is easier, note that you have to type the prefix before the \ref. The latest version (1999-03-05) seems to leave the prefix out of the label. I don’t exactly know why this is so.

Of course, you can also set up \p@enumi properly in the second example above. But perhaps that defeats the purpose of using enumerate? :)

No Comments :(