2

how to get Figures with proper numbers using Figure \ref{x}?

I have tried to compile twice my .tex document but it does not help. The warning I got is the following: \label whitout proper reference. I don´t know what to do anymore :/.

Figure \ref{Schematic_representation_of_a_spectrophotometer}`

\begin{figure}[h!]

    \centering
        \makebox[\textwidth]{
            \includegraphics[scale=1]{./Spectroscopy_and_microscopy_techniques/media/abs.png}
            \caption[Schematic representation of a spectrophotometer. ] {\textbf{Schematic representation of a spectrophotometer. }{ description.}}}
            \label{Schematic_representation_of_a_spectrophotometer}     
\end{figure}

Then after I compiled many times, I have Figure ??

Thanks

  • 1
    The \makebox does not look to be doing anything useful there, and will generate errors with many caption settings. But it is also stopping \label working unless you also move \label into the same box. – David Carlisle Mar 7 '17 at 13:10
  • Hi, welcome. Note that this site doesn't work quite like a normal forum, answer posts are reserved for solutions to the problem posed in the question. Hence, the two "answers" you posted below will soon be deleted. The one about the warnings would have been better suited as an edit to your question, and the other one should rather have been a comment. – Torbjørn T. Mar 7 '17 at 13:28
2

As David Carlisle pointed out the problem seems to be in the \makebox. Try to remove it. As a remark I also changed the positioneing argument to [htb], especially for large picture the [h!] can be problematic for TeX.

\documentclass{article}
\usepackage{graphicx}
\begin{document}
Figure \ref{Schematic_representation_of_a_spectrophotometer}

\begin{figure}[htb]
  \centering
  \includegraphics[scale=0.5]{example-image}
  \caption[Schematic representation of a spectrophotometer. ] {\textbf{Schematic representation of a spectrophotometer. }{ description.}}
  \label{Schematic_representation_of_a_spectrophotometer}     
\end{figure}

\end{document}

enter image description here

If the aim is to have the picture the same width as the text, the figure environment can be written

\begin{figure}[htb]
  \includegraphics[width=\linewidth]{example-image}
  \caption[Schematic representation of a spectrophotometer. ] {\textbf{Schematic representation of a spectrophotometer. }{ description.}}
  \label{Schematic_representation_of_a_spectrophotometer}     
\end{figure}

enter image description here

  • Since the OP's objective appears to be to make the graph as wide as the text block, I would also replace [scale=0.5] with [width=\textwidth]. Doing so would also permit getting rid of the superfluous \centering directive. – Mico Mar 7 '17 at 13:24
  • @Mico You are probably right, I added it. It is not entirely clear from the question since the \makebox is \textwidth but the picture has scale=1. – StefanH Mar 7 '17 at 13:50

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.