2

I'm trying to do a new float called "grafico" with the float package. It works fine, but when I try to do a reference, i.e. \autoref{}, it only shows the float number (e.g. If it's "Gráfico 2.1: blah blah", It only shows "2.1" when I use \autoref{}, and I want it to say "Gráfico 2.1".

Here is my code:

\documentclass[11pt,a4paper,table]{report}
\usepackage[spanish,es-tabla,english]{babel}
\addto\shorthandsspanish{\spanishdeactivate{~<>}}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage{graphicx}

\usepackage{float}
\newfloat{grafico}{thp}{lop}
\floatname{grafico}{Gráfico}
\renewcommand{\thegrafico}{\arabic{chapter}.\arabic{grafico}}
\renewcommand{\thegrafico}{\arabic{section}.\arabic{grafico}}

\usepackage[
        colorlinks=true,
        linkcolor=blue,
        urlcolor=blue]{hyperref}
.
.
\begin{document}
\selectlanguage{spanish}
.
.
some text here...
.
.
\begin{grafico}[!h]
        \begin{center}
            \includegraphics[width=1\textwidth]{riskplot.pdf}
            \caption{Porcentaje de los riesgos por región.}
            \label{graf:riskplot}
        \end{center}
\end{grafico}
.
.
See \autoref{graf:riskplot} for more information...
.
.
\end{document}

I'm using TexMaker on Windows 7. Can anybody help me? Thanks in advance!

  • \autoref{..} is a command from the hyperref package. Your MWE doesn't include it. Try, if this is source of your problem. – Zarko Nov 2 '15 at 2:35
  • @Zarko, I forgot to put it, sorry about that, I have a really long preamble.. thanks! (I already edited the question) – Jorge V Nov 2 '15 at 2:40
  • IYou need to define '\autoref' name ... see my answer. – Zarko Nov 2 '15 at 2:47
  • @Zarko, can you be a little more specific please? I'm new at this, and I know I might need to edit the \autoref command, but the thing is how can I do it? I tried checking the package documentation but didn't got to solve the problem.. thanks! – Jorge V Nov 2 '15 at 2:49
1

It seems, that hyperref package is not aware of new float name, so it is necessary to define it with:

\def\graficoautorefname{Gráfico}

Complete code (without Spanish babes, since I haven't it installed):

\documentclass[11pt,a4paper,table]{report}
%\usepackage[spanish,es-tabla,english]{babel}
%\addto\shorthandsspanish{\spanishdeactivate{~<>}}
    \usepackage[utf8]{inputenc}
    \usepackage[T1]{fontenc}
    \usepackage{lmodern}
    \usepackage{graphicx}
\usepackage{float}
\newfloat{grafico}{thp}{lop}
\floatname{grafico}{Gráfico}
\renewcommand{\thegrafico}{\arabic{chapter}.\arabic{grafico}}
\renewcommand{\thegrafico}{\arabic{section}.\arabic{grafico}}
    \def\graficoautorefname{Gráfico}% <--- added!
\usepackage[
        colorlinks=true,
        linkcolor=blue,
        urlcolor=blue]{hyperref}

    \begin{document}
%\selectlanguage{spanish}
some text here...
\begin{grafico}[!h]
        \begin{center}
            \includegraphics[width=0.5\textwidth]{example-image}
            \caption{Porcentaje de los riesgos por región.}
            \label{graf:riskplot}
        \end{center}
\end{grafico}
See \autoref{graf:riskplot} for more information...
    \end{document}

This gives:

enter image description here

| improve this answer | |
  • Amazing, I really appreciate your time. Thanks @Zarko, works great! – Jorge V Nov 2 '15 at 2:52

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.