This might look weird but it is culture specific. Is it possible to somehow change autoref to render "1 Figure" instead of "Figure 1"?
Asked
Active
Viewed 524 times
3
-
1Probably, can you make a MWE? – samcarter_is_at_topanswers.xyz Jun 19 '17 at 19:19
2 Answers
4
I found this subject here: Gobbling an argument if it starts with #
And I changed it to give you the required result.
The code is:
\makeatletter
% this is found in latex.ltx:
% \def\@car#1#2\@nil{#1}
\def\iffirsttoken#1#2{%
% define \@first@token to be the once expanded \@car of the first argument
% i.e. the first token or balanced group:
\expandafter\def\expandafter\@first@token\expandafter{\@car#1\@nil}%
% test if the expansion of \@first@token is the same as #2:
\expandafter\ifx\@first@token#2\relax
\expandafter\@firstoftwo
\else
\expandafter\@secondoftwo
\fi
}
\usepackage{hyperref}
\let\oldhref\autoref
\renewcommand{\autoref}[1]{%
%\oldhref{#1}%
\iffirsttoken{#1}{t}{~\ref{#1} Table}%
}
and your tables (only them) have to start with the letter t as first letter of their label...
Test it... You can expand the code for figures etc
Edit MWE:
\documentclass[a4paper,10pt]{article}
\usepackage[utf8]{inputenc}
\usepackage{tikz}
\makeatletter
% this is found in latex.ltx:
% \def\@car#1#2\@nil{#1}
\def\iffirsttoken#1#2{%
% define \@first@token to be the once expanded \@car of the first argument
% i.e. the first token or balanced group:
\expandafter\def\expandafter\@first@token\expandafter{\@car#1\@nil}%
% test if the expansion of \@first@token is the same as #2:
\expandafter\ifx\@first@token#2\relax
\expandafter\@firstoftwo
\else
\expandafter\@secondoftwo
\fi
}
\usepackage{hyperref}
\let\oldhref\autoref
\renewcommand{\autoref}[1]{%
%\oldhref{#1}%
\iffirsttoken{#1}{t}{~\ref{#1} Table}\relax%
\iffirsttoken{#1}{f}{~\ref{#1} Figure}%
}
\title{}
\author{}
\begin{document}
\begin{table}
\centering
\caption{}\label{tst}
\begin{tabular}{ c c}
\hline
Here & is\\
a & table\\\hline
\end{tabular}
\end{table}
We can refer to the table as Table \ref{tst}
with the \verb|\ref| command or to refer with
\verb|\autoref| and have \autoref{tst}
\begin{figure}
\centering
\caption{}\label{fst}
\begin{tikzpicture}
\draw[fill=blue] (0,0) rectangle (2,1);
\end{tikzpicture}
\end{figure}
We can refer to the figure as Figure \ref{fst}
with the \verb|\ref| command or to refer with
\verb|\autoref| and have \autoref{fst}
\end{document}
and the result
koleygr
- 20,105
4
As a general solution for different kind of floats (figures, tables, algorithms, etc.) you can redefine \autoref using the number from \ref followed by the float name, without the number, from \nameCref (provided by the package cleveref). If you also want to change the captions then you can declare a custom format using the caption package.
MWE:
\documentclass{article}
\usepackage{caption}
\DeclareCaptionLabelFormat{switched}{#2 #1}
\captionsetup{labelformat=switched}
\usepackage{hyperref}
\usepackage{cleveref}
\renewcommand{\autoref}[1]{\hyperref[#1]{\ref*{#1} \nameCref{#1}}}
\begin{document}
\begin{figure}
\centering
\fbox{this is a figure}
\caption{a caption}
\label{fig:example}
\end{figure}
See \autoref{fig:example} for an example.
\end{document}
Result:
Marijn
- 37,699
-
nice solution... It change the captions too... mine doesn't change the captions – koleygr Jun 19 '17 at 19:55

