3

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?

3
  • 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
    Commented Feb 13, 2014 at 6:38
  • Did you read Question mark instead of citation number completely? Commented Feb 13, 2014 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
    Commented Feb 13, 2014 at 20:32

1 Answer 1

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.

3
  • 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
    Commented Feb 13, 2014 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
    Commented Feb 13, 2014 at 6:32
  • @user28435 Did you try compiling my example code exactly as it is? What was the result after two compilations? Commented Feb 13, 2014 at 12:13

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .