1

In How use cleveref to get theorem-like name and list item number? the answer provides a way to cause \cref links to cite the numbers of items within an unnumbered theorem-like environment. It uses enumitem, among other things.

The example given there is as follows, but with one minor modification here such as I need: the actual item labels have additional formatting specified by the label key, namely, \setlist[problemsenum,1]{...} command, namely:

label=\bfseries\sffamily\arabic*.

Unfortunately, this causes the corresponding \cref links also to include that formatting (bold, sans-serif, and followed by a period).

Is there a way of removing that additional formatting in the links?

The source, with my modification of that label key, is:

\documentclass[oneside]{book}

\usepackage{amsthm}
\usepackage{thmtools}
\usepackage{enumitem}

\usepackage[colorlinks,linkcolor=blue]{hyperref} % hyperref added  
\usepackage{aliascnt}
\usepackage[nameinlink]{cleveref}

\declaretheoremstyle[
  headformat=\NAME\NOTE,
]{probs}
\declaretheorem[
  name=PROBLEMS,
  style=probs,
]{problemsinner}
\newenvironment{problems}
  {\problemsinner Solve these problems.}
  {\endproblemsinner}

\newlist{problemsenum}{enumerate}{1}
\setlist[problemsenum,1]{label=\bfseries\sffamily\arabic*.}  % label mod here}
\makeatletter
\renewcommand{\p@problemsenumi}{\maybe@thechapter{\thechapter}}
\protected\def\maybe@thechapter#1{%
  \ifnum#1=\value{chapter}%
  \else
    #1.%
  \fi
}
\makeatother

\crefformat{problemsenumi}{#2Problem~#1#3}
\Crefformat{problemsenumi}{#2Problem~#1#3}
\crefformat{problemsinner}{#2#3}
\Crefformat{problemsinner}{#2#3}

\begin{document}

\chapter{First}\label{chap:1}

See \cref{prob-part:first-problem} in a different chapter.

\chapter{Second}\label{chap:2}

Refer to \cref{prob-part:first-problem} in this chapter.

\begin{problems}
\label{prob:my-problems}

\begin{problemsenum}

\item \label{prob-part:first-problem}
First problem.

\item 
Second problem.

\end{problemsenum}

\end{problems}

\end{document}

As this part of an output page shows, in the link "Problem 2.1.", there is an unwanted period after "2.1", and both the "1" and the period are in bold sans-serif. I want no period there and normal text, not bold or sans-serif.

enter image description here

1 Answer 1

1

Changing the label=... changes the type was is set as the referenced value as well, however, enumitem provides the ref= option.

If you don't want bold/sans serif and without dot, then say ref={\arabic*} -- this way the reference value will be just the number.

\documentclass[oneside]{book}

\usepackage{amsthm}
\usepackage{thmtools}
\usepackage{enumitem}

\usepackage[colorlinks,linkcolor=blue]{hyperref} % hyperref added  
\usepackage{aliascnt}
\usepackage[nameinlink]{cleveref}

\declaretheoremstyle[
  headformat=\NAME\NOTE,
]{probs}
\declaretheorem[
  name=PROBLEMS,
  style=probs,
]{problemsinner}
\newenvironment{problems}
  {\problemsinner Solve these problems.}
  {\endproblemsinner}

\newlist{problemsenum}{enumerate}{1}
\setlist[problemsenum,1]{label={\bfseries\sffamily\arabic*.},ref={\arabic*}}  % label mod here}
\makeatletter
\renewcommand{\p@problemsenumi}{\maybe@thechapter{\thechapter}}
\protected\def\maybe@thechapter#1{%
  \ifnum#1=\value{chapter}%
  \else
    #1.%
  \fi
}
\makeatother

\crefformat{problemsenumi}{#2Problem~#1#3}
\Crefformat{problemsenumi}{#2Problem~#1#3}
\crefformat{problemsinner}{#2#3}
\Crefformat{problemsinner}{#2#3}

\begin{document}

\chapter{First}\label{chap:1}

See \cref{prob-part:first-problem} in a different chapter.

\chapter{Second}\label{chap:2}

Refer to \cref{prob-part:first-problem} in this chapter.

\begin{problems}
\label{prob:my-problems}

\begin{problemsenum}

\item \label{prob-part:first-problem}
First problem.

\item 
Second problem.

\end{problemsenum}

\end{problems}

\end{document}

enter image description here

1
  • @murray: You're welcome. (And yes, enumitem is a very sophisticated package -- unfortunately it's not written by me :-( )
    – user31729
    Sep 8, 2016 at 18:41

You must log in to answer this question.

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