3

I'm using a custom counter with a newenvironment for the first time and don't quite understand the nuances. The only problem I have so far is that when I use \ref it gets the number I want but not the format I want. I want the reference to have the same format as the original numbering. In this MWE the commented out line has what I want the format to be. What's the right way to get that?

\documentclass[12pt]{article}
% problem numbering
\newcounter{pcntr} % count the problems
\newenvironment{Problems}{ 
    \begin{list}{\textbf{\alph{pcntr})~}}{\usecounter{pcntr}}
}{
    \end{list}
}

% problem referencing
%\newcommand{\qref}[1]{part~\textbf{\alph{\ref{#1}})}}
\newcommand{\qref}[1]{part~\textbf{\ref{#1})}}



\begin{document}

\begin{Problems}
\item \label{prb:test1} Blah blah blah
\item \label{prb:test2} As we saw in \qref{prb:test1}, \dots
\item \label{prb:test3} Also, \qref{prb:test2} is quite interesting.

\end{Problems}
\end{document}
3

Use \thepcntr after defining it properly.

\documentclass[12pt]{article}

% problem numbering
\newcounter{pcntr} % count the problems
\renewcommand{\thepcntr}{\alph{pcntr}}

\newenvironment{Problems}
 {\begin{list}{\textbf{\thepcntr)~}}{\usecounter{pcntr}}}
 {\end{list}}

% problem referencing
\newcommand{\qref}[1]{part~\textbf{\ref{#1})}}



\begin{document}

\begin{Problems}
\item \label{prb:test1} Blah blah blah
\item \label{prb:test2} As we saw in \qref{prb:test1}, \dots
\item \label{prb:test3} Also, \qref{prb:test2} is quite interesting.

\end{Problems}
\end{document}

enter image description here

2

You may want to use of the facilities of the enumitem and cleveref packages to achieve your formatting objectives.

enter image description here

An advantage of using \cref is that you can cross-reference more than one item ("part") at a time. For instance, writing \Cref{prb:test2,prb:test1} are both quite interesting. would yield "Parts a) and b) are both quite interesting."

\documentclass[12pt]{article}

\usepackage{enumitem}
\newlist{Problems}{enumerate}{1} % define a new enumerate-like environment
\setlist[Problems]{label=\bfseries\alph*)}

\usepackage{cleveref}
\crefname{Problemsi}{part}{parts} % prefix for cross-references

\begin{document}

\begin{Problems}
\item \label{prb:test1} Blah blah blah
\item \label{prb:test2} As we saw in \cref{prb:test1}, \dots
\item \label{prb:test3} Also, \cref{prb:test2} is quite interesting.
\end{Problems}
\end{document}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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