0

I have already searched in the forum but also in similar questions I have not found solutions that work for my case. I'm working with \documentclass[italian,11pt,a4paper]{article} and I have a \ref{} inside a \caption :

\begin{figure}[htbp]
\begin{center}
\includegraphics[width=0.9\textwidth]{plots/delta}\hfil
\caption{bla bla bla in tabel \ref{deltatab}.}
\label{lab}
\end {center}
\end{figure}

And then the table:

\begin{table}[htbp]\label{deltatab}
\centering
\begin{tabular}{ccccccccc}
\hline
Filter & r & i & z & Y & J & Kw & Kd \\ \hline
 $\Delta mag$ &  0.27 & 0.18 & 0.15 & 0.30 & 0.19 & 0.62 & 0.45\\ \hline
\end{tabular}
\caption{some caption.}
\end{table}

But within the caption of the figure this produces me a figure ??. This is my package list:

\usepackage[italian]{babel}
\usepackage[latin1]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{newlfont}
\usepackage[english]{varioref}
\usepackage{hyperref}
\usepackage{graphicx}
\usepackage{color}
\usepackage{booktabs}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{mhchem} 
\usepackage{lmodern} 
\usepackage{subcaption}
\usepackage{bmpsize}
\usepackage{multirow}
\usepackage[labelfont={bf}, textfont={small}]{caption}
\usepackage{fancyhdr}
\newcommand{\fncyblank}{\fancyhf{}}

\usepackage{braket}
\usepackage{mathtools}
\usepackage{newlfont}
\usepackage{listings}
\usepackage{verbatim}
\usepackage[dvipsnames]{xcolor}

\usepackage{quoting}
\quotingsetup{font=small}

\usepackage{booktabs}
\usepackage{lscape}

\usepackage{geometry}
\geometry{hmargin={3cm,3cm},vmargin={3cm,3cm}}
\usepackage{titlesec}
\titlespacing{\chapter}{3em}{1em}{1em}
\fancyhf{}
\cfoot{\thepage}
\pagestyle{fancy}

Some ideas?

1 Answers1

1

You can achieve the desired reference by placing the labelof the table after its caption as shown in the following example. Some more information can be found here: Why does an environment's label have to appear after the caption?

\documentclass{article}
\usepackage{graphicx}
\usepackage[labelfont={bf}, textfont={small},textformat=period]{caption}
\usepackage[english]{varioref}
\usepackage{hyperref}


\begin{document}
\begin{figure}[htbp]
\centering
\includegraphics[width=0.9\textwidth]{example-image}
\caption{bla bla bla in tabel \ref{deltatab}}
\label{lab}
\end{figure}

\begin{table}[htbp]
\centering
\begin{tabular}{ccccccccc}
\hline
Filter & r & i & z & Y & J & Kw & Kd \\ \hline
 $\Delta mag$ &  0.27 & 0.18 & 0.15 & 0.30 & 0.19 & 0.62 & 0.45\\ \hline
\end{tabular}
\caption{some caption}
\label{deltatab}
\end{table}

\end{document}

enter image description here

In the above MWE, I have also added textformat=period to the caption options. This way, your captions are automatically followed by a dot and you don't have to include it manually into every caption.

Please also keep in mind the correct loading order of packages, especially regarding hyperref. This packages should generally (with some few exceptions) be the last package loaded. Also avoid loading packages more than once.

leandriis
  • 62,593