# TeXmaker doesn't show subfigure's reference number

I am running a main.tex file in which I use the \input{} command for my subfiles: subfile1.tex, ... Now, I have some figures in my subfiles, say subfile1.tex, and I want to insert a reference to that figure (both in the subfile1.tex itself and in the main.tex) using a \ref{fig:my_figure} command. Unfortunately this does not work, any clue?

For completeness I drop my code here, this is main.tex:

\documentclass[12pt]{article}
\usepackage{graphicx}

\begin{document}

\input{subfile1.tex}

Look at figure \ref{fig:my_figure}

\end{document}


while this is subfile.tex:

\begin{figure}
\includegraphics[width=4cm]{logo.png}
\label{fig:my_figure}
\end{figure}

Look at figure \ref{fig:my_figure}


Put any image in place of my logo.png and try yourself. In my case, when I run main.tex (in TeXmaker) it shows me neither of the two references.

• Please also note that subfigure and subfile means something completely different in the latex world, so be careful not to mixed them up Nov 17, 2020 at 12:09
• thanks! didn't know that Nov 17, 2020 at 12:33

The problem her is that the figure env it self does not provide anything the label can refer to. It is the \caption command that provides a figure number that the \label can refer to.

Here is an example:

\begin{filecontents}[overwrite]{sub-\jobname.tex}
\begin{figure}
\rule{4cm}{4cm}
\caption{test}
\label{fig:my_figure}
\end{figure}

Look at figure \ref{fig:my_figure}

\end{filecontents}

\documentclass[12pt]{article}
\usepackage{graphicx}

\begin{document}

\input{sub-\jobname.tex}

Look at figure \ref{fig:my_figure}

\end{document}