1

Code:

\documentclass{article}
\usepackage[a4paper]{geometry}
\usepackage[utf8]{inputenc}
\usepackage{cleveref}
\crefdefaultlabelformat{#2#1#3}
\begin{document}
\begin{enumerate}
\item Sum \label{sum}
\item VAT \label{vat}
\item Total $=(\cref{sum}) + (\cref{vat})$
\end{enumerate}
\end{document}

Output:

enter image description here

How to change the link format from "item 1" to "1". So I had "Total = (1) + (2)"?

  • Is there any reason you can't use \ref? – Dan Nov 7 '16 at 19:20
  • @Dan No, I used crefs accidentally by copying an example from the Internet. – user4035 Nov 8 '16 at 5:31
2

You could use \labelcref instead of \cref, or you could run \crefformat{enumi}{...} to perform a low-level reset of how \cref outputs cross-references to single instances of items (pun intended...) of type enumi. If you use the second option, you can instruct LaTeX to surround the item number with left and right parentheses automatically.

enter image description here

\documentclass{article}
\usepackage[a4paper]{geometry}
\usepackage[utf8]{inputenc}
\usepackage{amsmath,cleveref}
%\crefdefaultlabelformat{#2#1#3}

\begin{document}
\noindent
Strategy A: Use \verb+\labelcref+ instead of \verb+\cref+
\begin{enumerate}
\item Sum \label{sum1}
\item VAT \label{vat1}
\item $\text{Total}=(\labelcref{sum1}) + (\labelcref{vat1})$
\end{enumerate}

\bigskip
\noindent
Strategy B: Run \verb+\crefformat{enumi}{#2\textup{(#1)}#3}+
\crefformat{enumi}{#2\textup{(#1)}#3}
\begin{enumerate}
\item Sum \label{sum2}
\item VAT \label{vat2}
\item $\text{Total}=\cref{sum2} + \cref{vat2}$
\end{enumerate}
\end{document}
1

The usual \ref command doesn't try to be clever and just prints the number. In addition, you can customize the \cref references to enumerate items by using \crefname{enumi}{}{}. This uses an empty 'name' for the top-level enumerate counter. The enumerate environment uses counters enumi, enumii, etc. for the different levels. You can localize this to the enumerate environment by putting it inside the environment:

\begin{enumerate}
\crefname{enumi}{}{}
\item Sum \label{sum}
\item VAT \label{vat}
\item Total $=(\cref{sum}) + (\cref{vat})$
\end{enumerate}

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.