0

I want to have the reference number of the figure referring to the figure number (1) and not the subsection number (1.1). What shall I do?

Here is the output:

enter image description here

Here is the code:

\documentclass[a4paper, 10pt]{article}
\usepackage{float} 
\usepackage{graphicx}
\usepackage{caption}
\usepackage{subcaption}
\usepackage{xcolor}
\usepackage[colorlinks]{hyperref}
\usepackage{lipsum}
\renewcommand{\familydefault}{\sfdefault}
\hypersetup{
    colorlinks,
    filecolor=magenta,
    linkcolor=blue,
    citecolor=blue,      
    urlcolor=cyan,
    final
}
\definecolor{myblue}{RGB}{0, 32, 255}
\usepackage{caption}
\usepackage{xurl}
\usepackage{multirow}
\usepackage{multicol}
\begin{document}
\title{\vspace{-2.0cm}
blabla
}
\author{\small Name of author}
\date{\vspace{-3ex}}
\maketitle
\begin{multicols}{2}
\vspace{-1cm}
\section{section 1}
\subsection{subsection 1}%\label{Complexity_of_MR}
\vspace{-0.2cm}
(figure reference
\ref{example-image-a}). 
\begin{figure}[H]
  \vspace{-0.4cm}
  \begin{center}
%    \includegraphics[width=0.48\textwidth]{figures/MR_mechanisms_01.png}
    \includegraphics[width=0.48\textwidth]{example-image-a}
  \end{center}
  \caption{caption}
\end{figure}\label{example-image-a}
\noindent
\end{multicols}
\end{document}

ecjb
  • 883
  • 3
    You should put \label inside the figure environment, just after \caption. – Bernard May 24 '22 at 08:34
  • yes thank you @Bernard! – ecjb May 24 '22 at 08:35
  • 1
    And don't use center to center the figure, replace \begin{center} by \centering and remove \end{center}. The center env adds aspace above and below, as does figure. BTW: you generally shoulkd not use [H] placement. – daleif May 24 '22 at 08:51
  • Thank you for your comment @daleif. I removed the \begin{center}. I use the [H] placement so that the figure is positioned exactly where I want inside the text (and does not randomly get moved without [H]). Could you maybe give me then a good alternative for this? – ecjb May 24 '22 at 09:37
  • 1
    [H] is a bad idea, it leaves a big gab if the figure does not fit at this exact place. And you do not what the figure right here, you want it here about. Lear ro use the [htbp] placement, and never refer to a figure as below/above, etc always refer to the figure number. – daleif May 24 '22 at 09:52
  • @daleif - Somewhat related: https://tex.stackexchange.com/questions/208958/how-to-change-the-appearance-of-ref-depending-on-where-its-called-relative-to – John Kormylo May 24 '22 at 16:14

0 Answers0