3

I'm using ShareLatex and I'm trying to add a cross reference of a figure, but the result of the \ref{fig:sampe} only displays the number of the image and does not follow the format 'Figure 1' for example. I've tried with figure and subfigures and the result is the same.

Currently I'm using the following packages:

\usepackage{caption}
\usepackage{subcaption}
\usepackage{cleveref}

And also added the following lines:

\captionsetup[subfigure]{subrefformat=simple,labelformat=simple}
\renewcommand\thesubfigure{(\alph{subfigure})}

Does anyone knows why is this happening?

I've already checked the following posts this and this. Thanks in advance.

EDIT: I've added compilable code.

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{graphicx}

\usepackage{caption}
\usepackage{subcaption}

\usepackage[noabbrev,capitalize,nameinlink]{cleveref}
\captionsetup[subfigure]{subrefformat=simple,labelformat=simple}
\renewcommand{\figurename}{Figura}
\renewcommand\thesubfigure{(\alph{subfigure})}


\usepackage[
    backend=biber,
    sorting=none,
    urldate=edtf,
    date=edtf,
    seconds=true
]{biblatex}
\usepackage{url}
\usepackage{float}

\begin{document}

Some text, here it would have to appear the first reference \cref{fig:test1} , here it would have to appear the seconds reference \cref{fig:nav01_welcome}.

\begin{figure}[H] 
\begin{center}
\includegraphics[width=0.5\textwidth]{./images/navigation/nav01_welcome.png}
  \caption{Pantalla de bienvenida}
  \label{fig:test1}
\end{center}
\end{figure}  


\begin{figure}  
    \centering
    \begin{subfigure}[h]{0.48\textwidth}
        \centering
        \includegraphics[width=\textwidth]{./images/navigation/nav01_welcome.png}
        \caption{Arabic numerals}\label{fig:1a}     
        \label{fig:nav01_welcome}
    \end{subfigure}
    \quad
    \begin{subfigure}[h]{0.48\textwidth}
        \centering
        \includegraphics[width=\textwidth]{./images/navigation/nav02_welcome.png}
        \caption{Arabic numerals}\label{fig:1b}
    \end{subfigure}
    \caption{Capital Roman numerals}\label{fig:1}
\end{figure}

\end{document}
texuser
  • 33
  • 2
    have you tried using \cref{<key>}? Welcome to TeX.SE! – Troy May 13 '17 at 15:25
  • 3
    Welcome to TeX.SX! Please make your code compilable (if possible), or at least complete it with \documentclass{...}, the required \usepackage's, \begin{document}, and \end{document}. That may seem tedious to you, but think of the extra work it represents for TeX.SX users willing to give you a hand. Help them help you: remove that one hurdle between you and a solution to your problem. – Heiko Oberdiek May 13 '17 at 15:51
  • Thanks. I've edited my post to add the comilable code sample where the problem I'm facing can be reproduced. But anyway thanks @Troy, \cref{} did the trick. – texuser May 14 '17 at 08:11
  • 1
    How is this compilable? There is no documentclass line. You claimed to load package cleveref but the example doesn't show that either. – Johannes_B May 14 '17 at 08:21
  • Also, visitado en does not seem to be english. Why are you confusing yourself and others by saying so? – Johannes_B May 14 '17 at 08:23
  • Sorry, I seems that there was a mistake while editing the code. Now it's ok. – texuser May 14 '17 at 08:36
  • ./images/navigation/nav02_welcome.png doesn't work for anyone other than you. It would be better if you use example-image (which is in tex distributions for this reason) and check that the issue still occurs with the example in that form. Or since your question is not about the image, replace \includegraphics by IMAGE HERE or anything else. – David Carlisle May 14 '17 at 08:41
  • Not sure what you are asking for. \ref{label} is supposed to only output the number. On the other hand, \cref{label} adds the kind of counter you are referring to. And you already use that. What exactly is your question? – Johannes_B May 14 '17 at 08:44

1 Answers1

2

All is well if you load the cleveref package last -- and if you use \cref instead of \ref.

Two additional suggestions: Don't provide more than one \label per \caption. And, the three \centering instructions in the second figure environment may be eliminated if you replace \quad with \hfill.

enter image description here

\documentclass[demo,spanish]{article} % remove 'demo' option in real document
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{graphicx,babel,caption,subcaption}

\captionsetup[subfigure]{subrefformat=simple,labelformat=simple}
%\renewcommand{\figurename}{Figura}
\renewcommand\thesubfigure{(\alph{subfigure})}

% Load "cleveref" last:
\usepackage[noabbrev,capitalize,nameinlink]{cleveref}

\begin{document}

Here's the first cross-reference: \cref{fig:test}. 

Here's the second cross-reference: \cref{fig:2a}.

\begin{figure}[h]
\centering
   \includegraphics[width=0.5\textwidth]{./images/navigation/nav01_welcome.png}
   \caption{Pantalla de bienvenida}
   \label{fig:test}
\end{figure}  

\begin{figure}[h]
\begin{subfigure}{0.48\textwidth}
    \includegraphics[width=\textwidth]{./images/navigation/nav01_welcome.png}
    \caption{Arabic numerals}\label{fig:2a}     
\end{subfigure}%
\hfill
\begin{subfigure}{0.48\textwidth}
    \includegraphics[width=\textwidth]{./images/navigation/nav02_welcome.png}
    \caption{Arabic numerals}\label{fig:2b}
\end{subfigure}
\caption{Capital Roman numerals}\label{fig:2}
\end{figure}

\end{document}
Mico
  • 506,678