7

I have got a quick question; I am writing a document with lots of sections and figures. Cross referencing works fine. So far so good. However, I would prefer when I reference something to have the figures and the sections in different formats.

For instance if I reference a section (provided tha appropriate labels are in place) I would like the output to be: Section 4.3

and when I reference a figure to have: Figure 4-3.

How should I go about it?

Thank you in advance

Gonzalo Medina
  • 505,128
stratis
  • 223
  • 2
    Please provide a bit more information about how the objects are currently "numbered". For instance, are figure objects already numbered 4-1, 4-2, 4-3, etc (where 4 is probably the chapter number, correct?), or are they currently numbered as 4.1, 4.2, 4.3., etc? At any rate, you should have a look at the cleveref package, which provides nearly unlimited possibilities for low-level controls over the names and numbers used in cross-references. – Mico Aug 11 '12 at 00:21
  • All objects are currently numbered in the following format: x.y. What I need is to have sections referenced like x.x and figures referenced as x-y. – stratis Aug 11 '12 at 00:27
  • 1
    Do you maybe want to do a global reset of the numbering system of your figures from x.y to x-y? If you don't reset the numbering system, your readers may become confused by a figure's caption being numbered in x.y style but then being cross-referenced in x-y style. – Mico Aug 11 '12 at 02:36

1 Answers1

9

You can redefine \p@figure to produce the desired formatting (but this will only change the formatting of the string used for cross-references; the string used for captions will remain unaltered):

\documentclass{book}

\makeatletter \renewcommand\p@figure{\thechapter-\arabic{figure}\expandafter@gobble} \makeatother

\begin{document}

\chapter{Test Chapter} See figure~\ref{fig:test} in section~\ref{sec:test}...

\section{test}\label{sec:test} \begin{figure}[!ht] \caption{Test Figure} \label{fig:test} \end{figure}

\end{document}

enter image description here

And combining this with the cleveref package, you can say something like this:

\documentclass{book}
\usepackage{cleveref}

\makeatletter \renewcommand\p@figure{\thechapter-\arabic{figure}\expandafter@gobble} \makeatother

\crefname{figure}{figure}{figures} \Crefname{figure}{Figure}{Figures}

\begin{document}

\chapter{Test Chapter} See \cref{fig:test} in \cref{sec:test}...

\section{test}\label{sec:test} \begin{figure}[!ht] \caption{Test Figure} \label{fig:test} \end{figure}

\end{document}

enter image description here

Remarks:

  1. I only used [!ht] as placement specifier just for this example; I am not recommending its usage.
  2. As a personal opinion, this style introduces some level of inconsistency since we are referencing object x.y using a different string x-y. I would suggest you to reconsider this change.

For consistency's sake, I would prefer to change \thefigure so the strings used in the object numbering and the one used in the cross-reference will be the same:

\documentclass{book}
\usepackage{cleveref}

\makeatletter \renewcommand\thefigure{\mbox{\thechapter-\arabic{figure}}} \makeatother

\crefname{figure}{figure}{figures} \Crefname{figure}{Figure}{Figures}

\begin{document}

\chapter{Test Chapter} See \cref{fig:test} in \cref{sec:test}...

\section{test}\label{sec:test} \begin{figure}[!ht] \caption{Test Figure} \label{fig:test} \end{figure}

\end{document}

enter image description here

Gonzalo Medina
  • 505,128
  • I never meant to have different strings in between captions and cross references. I just wanted what you precisely describe in your second remark; Consistency between captions and references with different formats according to the kind of object referenced. Thank you. – stratis Aug 11 '12 at 07:34