A command like \autoref{eq:speed} outputs Equation~1. I.e. there is a blank (a protected space, I guess) between Equation and the number. How can this be changed, e.g. into a small space?
Asked
Active
Viewed 329 times
1
-
3only by changing/patching an internal definition. Imho if you want more sophisticated output a dedicated package like cleveref or zref is better. – Ulrike Fischer May 07 '20 at 18:27
1 Answers
1
~ (or \nobreakspace) is used to tie the "\autoref name" to its number. If you want a global change of \autoref to always use (say) \space, you can add
\usepackage{letltxmacro}
\let\oldautoref\autoref
\DeclareRobustCommand{\autoref}[1]{{\let\nobreakspace\space\oldautoref{#1}}}
to your preamble. This updates \nobreakspace to \space just for use with \autoref.
\documentclass{article}
\usepackage{hyperref}
\usepackage{letltxmacro}% https://tex.stackexchange.com/q/88001/5764
\begin{document}
Here is an equation:
\begin{equation}
f(x) = ax^2 + bx + c \label{eq:eqn}
\end{equation}
One two three four five six seven eight nine ten eleven twelve seven Equation~\ref{eq:eqn}.
One two three four five six seven eight nine ten eleven twelve seven Equation \ref{eq:eqn}.
One two three four five six seven eight nine ten eleven twelve seven \autoref{eq:eqn}.
% Update \autoref to replace \nobreakspace with \space
\LetLtxMacro\oldautoref\autoref
\DeclareRobustCommand{\autoref}[1]{{\let\nobreakspace\space\oldautoref{#1}}}
One two three four five six seven eight nine ten eleven twelve seven \autoref{eq:eqn}.
\end{document}
Werner
- 603,163
-
Great, your example works. However, I have a document class, which uses babel. And when adding
\usepackage{babel}in your example, it seems\nobreakspacecannot be overwritten. Do you understand this? – Friedrich -- Слава Україні May 07 '20 at 22:49 -
@Friedrich: Perhaps you can supply a complete but minimal document example that replicates the issue. Start with my code, then post it to Pastebin. – Werner May 07 '20 at 23:00
-
Your code is already fully fine as minimal example! But as said adding
\usepackage{babel}to it,\nobreakspaceis not overwritten. – Friedrich -- Слава Україні May 07 '20 at 23:08 -
Another challenge I have, is that it should apply only to
Equation, but not the rest asFigures, etc. – Friedrich -- Слава Україні May 07 '20 at 23:10 -
If you only want a breakpoint after the text "Equation", you can redefine the name:
\renewcommand\equationautorefname{Equation\hspace{0pt}}. – Ulrike Fischer May 08 '20 at 07:40 -
@Friedrich: If it is specifically for equations, then why not define an equation-specific reference, like
\eqautoref{..}:\newcommand{\eqautoref}[1]{\hyperref[#1]{Equation \ref*{#1}}}? – Werner May 08 '20 at 17:40
