1

I want to put a parentheses around the crossed reference and remove the parentheses around the number of the crossed reference, as in the below image.

enter image description here

I used cleveref package, I tried this

\documentclass{book}
\usepackage{color}
\usepackage{hyperref}
\hypersetup{colorlinks=true, linkcolor=cyan}
\usepackage{amsmath}
\usepackage{cleveref}
\crefname{equation}{(eq.}{eqs.}        
\crefname{section}{(sec.}{secs.}
\crefdefaultlabelformat{#2\textbf{\textup{#1}}#3)}
\creflabelformat{equation}{#2\textbf{\textit{\textup{#1}}}#3)}
\begin{document}
\chapter{Math}
\section{Equation}\label{sec:equation}
\begin{align}
A =& B (C + D) \label{eq:equation 1}\\
  =& B C + B D
\end{align}
see \cref{sec:equation} and \cref{eq:equation 1}
\end{document}

the problem is when I refer to multi equations or multi sections, which be as: enter image description here

any help with that?

  • 1
    Just so that I understand your objectives: Why is there a closing parenthesis, but no opening parenthesis, in the arguments of \crefdefaultlabelformat and \creflabelformat{equation}? – Mico Aug 27 '16 at 6:32
  • 1
    Please also post the code that generates the two screenshots you've posted. The color (cyan?) isn't set by cleveref, is it? – Mico Aug 27 '16 at 6:36
  • @Mico the opening parentheses is in \crefname and the closing is in \crefdefaultlabelformat and \creflabelformat{equation}, for the color it is just a test color and setting by hypersetup. – Muhammad Abdulrasool Aug 27 '16 at 10:01
2

For each item type to be cross-referenced -- equation, section, etc -- you need to provide \crefmultiformat and \crefrangeformat directives to state the formatting requirements explicitly. The former macro is used by the cleveref package to evaluate the argument of a \cref instruction if the argument consists of either exactly two items or if there are more than two items, with a gap somewhere in the items' numbers. The latter macro is used by cleveref either if the list of three or more items in the argument of \cref contains no gaps or if \crefrange{first-arg}{last-arg} is encountered.

In the example below, I show the code that's needed for equation items. I trust you can figure out how to provide similar instructions for section, figure, table, etc items.

Since you'll be providing explicit formatting instructions for single and multiple items, I would also like to suggest you drop the \crefdefaultlabelformat and \creflabelformat directives and that you use something like

\crefformat{equation}{(eq.~#2\textbf{\textup{#1}}#3)}

for each item type that needs to be cross-referenced via \cref. enter image description here

\documentclass{book}
\usepackage{amsmath} % for "gather" environment
\usepackage{xcolor}
\usepackage[colorlinks=true, linkcolor=cyan]{hyperref}
\usepackage{cleveref}

\crefformat{equation}{(eq.~#2\textbf{\textup{#1}}#3)}
\crefmultiformat{equation}%
   {(eqs.~#2\textbf{\textup{#1}}#3}% % first item in list
   { and~#2\textbf{\textup{#1}}#3)}% % second (if exactly two items)
   {, #2\textbf{\textup{#1}}#3}%     % middle (if more than two items)
   { and~#2\textbf{\textup{#1}}#3)}  % last   (if more than two items)
\crefrangeformat{equation}%
   {(eqs.~#3\textbf{\textup{#1}}#4 to~#5\textbf{\textup{#2}}#6)}

\begin{document}
\setcounter{chapter}{1}
\setcounter{section}{1}

\begin{gather}
A = B (C + D) \label{eq:mult}  \\
e^{i\pi}-1=0  \label{eq:euler} \\
a^2+b^2=c^2   \label{eq:pyth}  \\
E = m c^2     \label{eq:einst}
\end{gather}

\cref{eq:mult,eq:pyth}                   % two items

\cref{eq:mult,eq:pyth,eq:einst}          % three items, with gap

\cref{eq:mult,eq:euler,eq:pyth,eq:einst} % four items, no gap

\crefrange{eq:mult}{eq:einst}            % explicit range of items
\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.