2

I've followed tutorials online such as https://latex-tutorial.com/tutorials/figures/ and https://www.overleaf.com/learn/latex/How_to_Write_a_Thesis_in_LaTeX_(Part_3):_Figures,_Subfigures_and_Tables#Tables to create referable figures in my document, but all that is outputted is ?? in place of the figure. Here are the packages imported:

\usepackage[utf8]{inputenc}
\usepackage{booktabs} % for much better looking tables
\usepackage{array} % for better arrays (eg matrices) in maths
\usepackage{paralist} % very flexible & customisable lists (eg. enumerate/itemize, etc.)
\usepackage{verbatim} % adds environment for commenting out blocks of text & for better verbatim
\usepackage{subfig} % make it possible to include more than one captioned figure/table in a single float
\usepackage{multicol}
\usepackage[a4paper, total={8in, 8in}]{geometry}
\usepackage{appendix}
\usepackage{tabularx}
\usepackage{biblatex}%to cite articles
\usepackage{fancyhdr}
\addbibresource{ACS231.bib}%change the name of the file to a different .bib file
\usepackage{graphicx}
\usepackage{comment}

\graphicspath{ {./images/} }

Further down the document:

\begin{document}
\begin{multicols}{2}
\subsection{Electronics Design | Exercise 9}
Here is the electrical diagram.

\begin{figure}[h!] \centering \includegraphics[width=7cm]{finalSchematic.jpg} \caption{Schematic} \label{fig:schematic} \end{figure}

\figurename{\ref{fig:schematic}} \ref{fig:schematic}

\end{document} \end{multicols}{2}

Latek output

I tried this in the example program in Overleaf and it worked, suggesting its not the file itself. I'm inclined to think it may be packages interacting. I created a new file and pasted the entire code which gave the same issue. I've seen the issue arise because of incorrect syntax on other posts, but if it worked in the example file it doesn't suggest this is an issue of syntax. Any ideas?

Log shows this: enter image description here

No red circles are appearing, only a yellow warning that corresponds to the log. The line its referring to is:

\ref{fig:schematic}

which to me appears to be referencing something that is in fact labelled?

  • \figurename does't take an argument and is not usually used explicitly \figurename{\ref{fig:schematic}} would be expected to make figure?? on the first run. If you get an error do not look at the pdf look at the log file (do you have a red circle in overlearf?, show your log) – David Carlisle Apr 06 '21 at 21:20

2 Answers2

6

None of the packages you show are related to \ref (see below about multicol). \figurename makes the text figure (or translations of that) in almost all classes that have figures so it is very surprising that you get ?? not prefixed by figure or that you only get one ?? not two sonce you have two instances of \ref. It is unusual but not an error to use \figurename explicitly.

Are you sure no errors were shown (Overleaf only displays a small red circle as a hint to read the log)

Given

\documentclass{article}
\usepackage{graphicx}
\begin{document}

\subsection{Electronics Design | Exercise 9} Here is the electrical diagram.

\begin{figure}[h!] \centering \includegraphics[width=7cm]{example-image.jpg} \caption{Schematic} \label{fig:schematic} \end{figure}

\figurename{\ref{fig:schematic}} \ref{fig:schematic} \end{document}

after the first run it should look like

enter image description here

after the second run it should look like

enter image description here


Your updated question shows the cause:

enter image description here

If I add multicol to the example I get the same warning and same result:

enter image description here

\documentclass{article}
\usepackage{graphicx,multicol}
\begin{document}

\begin{multicols}{2}

\subsection{Electronics Design | Exercise 9} Here is the electrical diagram.

\begin{figure}[h!] \centering \includegraphics[width=7cm]{example-image.jpg} \caption{Schematic} \label{fig:schematic} \end{figure}

\figurename{\ref{fig:schematic}} \ref{fig:schematic}

\end{multicols}

\end{document}

As you used the figure where figures are not allowed it is essentially discarded so the \label was never activated and so the \ref reports it as an undefined label.

David Carlisle
  • 757,742
  • Reason behind putting \figurename{\ref{fig:schematic}} \ref{fig:schematic} was to help diagnose the error, not for use necessarily. I've now updated the post to show the log. No red circle is shown, only a yellow warning saying that \label{fig:Schematic} and \ref{fig:Schematic} don't have the same thing written in the brackets when they do! – sebzuddas Apr 06 '21 at 21:57
  • @Zuddas98 are you using a babel language that makes : active? If so, don't use : in label/ref.. Also it's OK to add stuff for debugging but it means that the image you posted was not made by the code you posted and as we can not run the code you posted it makes the question very hard to answer. You coudl take this working example and add code from your document to it until it breaks. – David Carlisle Apr 06 '21 at 22:31
  • @Zuddas98 oh now you have shown the log it is clear! I will update my answer. – David Carlisle Apr 06 '21 at 22:52
0

Multicols and figures mentioned in another answer struggle in their compatibility:

As you used the figure where figures are not allowed it is essentially discarded so the \label was never activated and so the \ref reports it as an undefined label.

Having followed the answer offered here: multicol and figures I managed to use the code offered to both reference and display the figure.

I added this at the beginning of the document underneath \usepackage :

\newenvironment{Figure}
  {\par\medskip\noindent\minipage{\linewidth}}
  {\endminipage\par\medskip}

and this to display and reference the figure:

\begin{Figure}
    \centering
        \includegraphics[width=\linewidth]{Images/finalSchematic.jpg}
    \captionof{figure}{Electronic schematics}
    \label{figschematics}
\end{Figure}%Capital F. Use captionof.

here is blah blah \ref{figschematics}