2

I am trying to reference figures with short path but every time I compile I get a blank space, the code I used is:

\documentclass[15pt,a4paper]{article}
\usepackage{lipsum}
\usepackage{url}
\usepackage[nochapters]{classicthesis}
\usepackage{graphicx}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{hyperref}
\usepackage{mathtools}
\usepackage{tabularx}
\usepackage{booktabs}
\usepackage[left=1.5in,right=1in,top=1in,bottom=1in]{geometry}

\graphicspath
    { 
    {Figures/}
    }

\begin{document}
\title{\rmfamily\normalfont\spacedallcaps{Title}}
\author{\spacedlowsmallcaps{Lorem Ipsum}}
\date{} % no date

\maketitle
\section*{This is a section}
This is just a \ref{fig:abcd}
\begin{figure}[h]
\begin{center}
\includegraphics[scale=1]{figure}
\caption{Lorem ipsum}
\end{center}
\label{fig:abcd}
\end{figure}
\end{document}
Werner
  • 603,163
nxkryptor
  • 1,478

1 Answers1

2

The scope of your caption's referencing capability is only within the group that you have. Why is this? Well, in a general setting, \label uses the most recent redefinition of \@currentlabel, and such re-definitions are local to the group they are made in.

In your example you've placed the \caption inside a center environment which provides a local group, yet the \label is outside that environment. So, \label never sees the appropriate \@currentlabel.

Remove the center environment and use \centering instead, which should clear things up.

enter image description here

\documentclass{article}
\usepackage[nochapters]{classicthesis}
\usepackage{graphicx}
\usepackage{hyperref}

\begin{document}

\section*{This is a section}
This is just a \ref{fig:abcd}.
\begin{figure}[h]
  \centering% https://tex.stackexchange.com/q/23650/5764
  \includegraphics[scale=.5]{example-image}
  \caption{Lorem ipsum}
  \label{fig:abcd}
\end{figure}

\end{document}
Werner
  • 603,163