1

I encountered a strange problem when referencing to figure in text. The link to the figure is established as is evidenced in the red box in the compiled PDF. But it is the question mark instead of figure number that is shown up in the red box. Could somebody help me troubleshoot this?

The PDF snapshot is here: enter image description here

The code is below (I used \usepackage{caption} to suppress the figure number in the caption, I swap the order of \caption and \label and it does not help):

\begin{description}
    \item[ideal market theorem:] the ideal market picture consists of an uptrend, top, downtrend, and bottom (figure~\ref{fig:DowIdealMarketPicture}), interspersed with retracements and consolidations, the purpose of the ideal market picture is to provide a generalized model of the stock market's price behavior over time, it presumes that prices \underline{oscillate} over long periods based on the accumulated \underline{emotion} of investors as well as the facts of the \underline{business cycle}
        \begin{figure}[hbt]
            \centering
            \includegraphics[scale=0.54]{Figure/DowIdealMarketPicture}
            \caption*{figure 2.1 the Dow theory ideal market picture}
            \label{fig:DowIdealMarketPicture}
        \end{figure}
\end{description}

The the log file contains the following warning message:

Package caption Warning: \label without proper reference on input line 150. See the caption package documentation for explanation.

8
  • 1
    you have used \caption* so there is no number and so nothing to \label Dec 1, 2020 at 16:17
  • @DavidCarlisle is there any way to suppress figure number in caption and at the same time show figure number in reference? Dec 1, 2020 at 16:27
  • why can you not use \caption as normal, then let latex generate Figure 2.1 then Figure~\ref{fig:DowIdealMarketPicture} can access the Figure 2.1 text as normal. Dec 1, 2020 at 16:28
  • 1
    Why do you want to write figure 2.1 "by hand"? Dec 1, 2020 at 16:28
  • You could of course do that but you would have no automated check that the actual figure number matched the text that looks like a figure number that you added to the caption so it would be very fragile and weird Dec 1, 2020 at 16:30

1 Answer 1

1

You'll have to set \@currentlabel manually. If you're using hyperref as well, then an additional \phantomsection should provide the correct hypertarget.

enter image description here

\documentclass{article}

\usepackage{caption,graphicx}
\usepackage{hyperref}

\makeatletter
\newcommand{\setrefnumber}{\phantomsection\renewcommand{\@currentlabel}}%
\makeatother

\begin{document}

\begin{description}
    \item[ideal market theorem:] the ideal market picture consists of an uptrend, 
    top, downtrend, and bottom (figure~\ref{fig:DowIdealMarketPicture}), interspersed 
    with retracements and consolidations, the purpose of the ideal market picture is 
    to provide a generalized model of the stock market's price behavior over time, it 
    presumes that prices \underline{oscillate} over long periods based on the 
    accumulated \underline{emotion} of investors as well as the facts of the 
    \underline{business cycle}
    
    \begin{figure}[hbt]
      \setrefnumber{2.1}%
      \centering
      \includegraphics[width = .5\linewidth]{example-image}
      \caption*{figure 2.1 the Dow theory ideal market picture}
      \label{fig:DowIdealMarketPicture}
    \end{figure}
\end{description}

\end{document}

Note how \setrefnumber{<whatever>} is placed at the top of the figure environment so the \reference hyperlink jumps to the top of the figure.

2
  • Use phantom section and set number referring to it, what a terrific trick! Many thanks Werner! Dec 1, 2020 at 17:14
  • AFAIK the caption package offers \phantomcaption, so I assume that this one could be used, too.
    – user205700
    Dec 1, 2020 at 22:01

You must log in to answer this question.

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