2

After visiting wiki on labels and cross-referencing, a couple of tex sites (1,2), and a stackexchange solution, the following reference will not appear in the caption. I'm using pdflatex on ubuntu.

The section label that is being referenced (appen) is defined at the end of the doc. All of the following attempts to insert the reference in the caption produce ?? or [?]:

\begin{figure}[!ht]
\caption*{See the ~\ref{appen} for language abbreviations.}
\makebox[\textwidth]{\includegraphics[width=100mm]{{/filepath/hourly.update}.pdf}}
\end{figure}

\begin{figure}[!ht]
\caption*{See the ~\cite{appen} for language abbreviations.}
\makebox[\textwidth]{\includegraphics[width=100mm]{{/filepath/hourly.update}.pdf}}
\end{figure}

\begin{figure}[!ht]
\caption*{See the ~\protect\ref{appen} for language abbreviations.}
\makebox[\textwidth]{\includegraphics[width=100mm]{{/filepath/hourly.update}.pdf}}
\end{figure}

\begin{figure}[!ht]
\caption*{See the ~\protect\cite{appen} for language abbreviations.}
\makebox[\textwidth]{\includegraphics[width=100mm]{{/filepath/hourly.update}.pdf}}
\end{figure}

\section{Appendix}
\label{appen}
\subsection{Language Abbreviations}
 ...words, figures, tables, and such.

-- edit 2013-02-12

Error received:

LaTeX Warning: Reference `appen' on page 2 undefined on input line 94

Any idea how to insert a reference within a caption?

  • As far as I can tell, this question does not share a relationship with the supposed duplicate. The error that I'm receiving is as follows: -- LaTeX Warning: Reference `appen' on page 2 undefined on input line 94 – blehman Feb 13 '14 at 6:38
  • Did you read Question mark instead of citation number completely? – Reinstate Monica - M. Schröder Feb 13 '14 at 7:24
  • Yes. BibTeX is not the problem nor is that package being used. The problem is occurring with a reference within a caption. Your link is a great explaination for another problem dealing with bibliographies. As you can see both in my question and in the answer, I'm labeling a section so ~\cite{} is not useful. Thanks for the help. – blehman Feb 13 '14 at 20:32
6

The first one (using \ref{appen}) will give you, after two compilations, the expected result. The ones using \cite (which is to be used for bibliographical items) are incorrect. The one using \protect\ref{appen} will also yield the correct result, but \protect is not necessary. An example (notice that leaving a blank space before ~ will produce a superfluous space):

\documentclass{article}
\usepackage[demo]{graphicx}
\usepackage{caption}

\begin{document}

\begin{figure}[!ht]
\caption*{See the Section~\ref{appen} for language abbreviations.}
\makebox[\textwidth]{\includegraphics[width=100mm]{{/filepath/hourly.update}.pdf}}
\end{figure}

\section{Appendix}
\label{appen}

\end{document}

enter image description here

The general mechanism for cross-referencing is to place

\label{<key>}

after an anchor has been generated (typically, after some automatic numbering has been done), and to use

\ref{<key>}

to cross-reference the labelled object.

The demo option for graphicx simply replaces actual figures with black rectangles; do not use that option in your actual document.

  • I really like that you warned about the demo option. I remember carrying over a lot of lipsums and similar example producing packages and options from answers on TeX.SX when I first started using the site. – Dennis Feb 13 '14 at 2:26
  • @Gonzalo, those suggestions were tried and still produce the same error -- LaTeX Warning: Reference `appen' on page 2 undefined on input line 94. -- Let me know if you have any other ideas. Thanks. – blehman Feb 13 '14 at 6:32
  • @user28435 Did you try compiling my example code exactly as it is? What was the result after two compilations? – Gonzalo Medina Feb 13 '14 at 12:13

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.