I am trying to label a figure outside of the float environment. I am using the command \label{} and \ref{}. Unfortunately, Latex does print the correct number of the figure. Does someone know how to fix this? Thank you in advance!
\documentclass{article}
\usepackage[utf8]{inputenc}
\title{b}
\author{}
\date{February 2021}
\begin{document}
\maketitle
\section{Introduction}
\begin{itemize}
\item f
\begin{center}
\includegraphics[width=0.5\textwidth]{Versuchsaufbau.JPG}
\label{fig:Versuchsaufbau}
\captionof{figure}{nj}
\end{center}
\end{itemize}
\end{document}

\labelcommand after\captionof{figure}{…}? – Bernard Feb 24 '21 at 14:51\captionof? The correct placement for\labelis\caption{<stuff>\label{<label>}}or\captionof{<type>}{<stuff>\label{<label>}}.\labelalways references the last increased counter. The counter is increased by\caption, that's why you have to put it either inside of or after\caption. But if you put it after\captionthis can lead to inconsistent spacing in some border cases, so inside of\captionis the best place (just make sure to not put a space before/after\label). – Skillmon Feb 24 '21 at 14:54\labelshould be after\captionof{...}{....}. – Zarko Feb 24 '21 at 15:25