Graphics, Figures & TablesCross references, using cref

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
RensR
Posts: 10
Joined: Wed Jan 14, 2015 2:55 pm

Cross references, using cref

Post by RensR »

Hi guys,
I have a problem with my cross references. I use the cleveref package. When I put in a figure, give it a caption and label and then use the reference, it won't say figure, but will say section instead. Also, it doesn't refer to the figure, but to the section it is in.
This is (essentially) my code:

Code: Select all

Code, edit and compile here:
\section{XRD}\label{sec:meth XRD}
text, not important.
\section{XRR}\label{sec:meth XRR}
Bunch of text, explaining stuff about XRR. Let us see that in \cref{fig:XRR Reflection}.
\begin{figure}[h!]
\begin{center}
\includegraphics[width=0.8\textwidth]{Reflection.pdf}
\caption{Reflection and refraction.}
\end{center}
\label{fig:XRR Reflection}
\end{figure}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
This produces a cross reference, which says "Let us see that in section 1.2." Instead it should say figure 1 (or 1.1 (chapter,number of figure) or 1.2.1 (chapter,section,#of figure) of course. Also, how to make that set up of figure numbering, I would like the 1.2.1 there (or will that work automatically?)

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

rais
Posts: 419
Joined: Sun Nov 16, 2014 8:51 pm

Cross references, using cref

Post by rais »

Hi there,
RensR wrote:
I have a problem with my cross references. I use the cleveref package. When I put in a figure, give it a caption and label and then use the reference, it won't say figure, but will say section instead. Also, it doesn't refer to the figure, but to the section it is in.
This is (essentially) my code:

Code: Select all

Code, edit and compile here:
\section{XRD}\label{sec:meth XRD}
text, not important.
\section{XRR}\label{sec:meth XRR}
Bunch of text, explaining stuff about XRR. Let us see that in \cref{fig:XRR Reflection}.
\begin{figure}[h!]
\begin{center}
\includegraphics[width=0.8\textwidth]{Reflection.pdf}
\caption{Reflection and refraction.}
\end{center}
\label{fig:XRR Reflection}
\end{figure}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
your problem may be, that you're using the \caption command inside a center environment, but the according \label command after it. In that case, a simple moving of the \label command before \end{center} might do.
On the other hand, the figure and center environments both add vertical space---I'd replace the center environment here with a \centering command instead.

Because of the missing Infominimal working example, I didn't test it, though.

KR
Rainer
RensR
Posts: 10
Joined: Wed Jan 14, 2015 2:55 pm

Cross references, using cref

Post by RensR »

Thanks for the effort, but that did not solve it sadly.
Let me explain some more. I am working with subfiles, so I have a main file Report.tex:

Code: Select all

Code, edit and compile here:
\usepackage{Huge list of packages}
\usepackage{cleveref}
\crefname{equation}{equation}{equations}
\crefname{figure}{figure}{figures}
\crefname{section}{section}{sections}
\begin{document}
\begin{titlepage}
here i define my preferences for my titlepage
\\
\end{titlepage}
\begin{abstract}
where the abstract will go
\end{abstract}
\tableofcontents
\subfile{Theory/Theory.tex
\subfile{Methodology/Methodology.tex}
\bibliographystyle{ieeetr}
\bibliography{References/Bibliography.bib}
\appendix
\subfile{Appendix/AppendixA.tex}
\end{document}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
And then I have multiple subfiles in the according folders, which works fine. Then in each of the folders I have:

Code: Select all

Code, edit and compile here:
\documentclass[../Report.tex]{subfiles}
\graphicspath{{Methodology/}}
\begin{document}
\chapter{Methodology}\label{chap:Methodology}
\section{Pulsed Laser Deposition}\label{sec:meth PLD}
\section{X-Ray Diffraction}\label{sec:meth XRD}
\begin{equation}
\label{eq:XRD Bragg}
n\lambda=2d\sin(\theta)
\end{equation}
\cref{eq:XRD Bragg}
\section{X-Ray Reflectivity}\label{sec:meth XRR}
Bunch of text, as can be seen in \cref{fig:XRR Reflection}.
\begin{figure}[h!]
\centering
\includegraphics[width=0.8\textwidth]{Reflection.pdf}\label{fig:XRR Reflection}
\label{fig:XRR Reflection}
\caption{Reflection and refraction of X-rays on material surface.}
\end{figure}
\end{document}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
In which the figure works, the equation works, the caption at the figure works, the reference to the equation says "equation (2.1)",, so that all works fine. The reference to the figure however, says "section 2.3" (this is if I run Report.tex, if I run Methodology.tex, it will give 1.something of course). I hope this makes it clearer and someone might me able to help.
RensR
Posts: 10
Joined: Wed Jan 14, 2015 2:55 pm

Cross references, using cref

Post by RensR »

For some, not apparent to me, reason, it suddenly decided to start working. I can't figure out why it wasn't working before, but it is now.
Apparently, compiling a few times worked. I now have the figure environment like below, which works fine.

Code: Select all

Code, edit and compile here:
\begin{figure}[h!]
\centering
\includegraphics[width=0.8\textwidth]{Reflection.pdf}
\caption{Reflection and refraction of X-rays on material surface.}\label{fig:XRR Reflection}
\end{figure}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
lirkov
Posts: 1
Joined: Fri Sep 04, 2015 4:10 pm

Re: Cross references, using cref

Post by lirkov »

The \label command should be placed after the \caption command. Otherwise the \ref command returns wrong number.
Post Reply