Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I am using the captionand subcaption package with floatrow and would like to change how references with \ref are formated.

First here is my captionsetup so far:

\DeclareCaptionSubType[alph]{figure}
\captionsetup[subfigure]{labelformat=brace,justification=centerlast}
\captionsetup{subrefformat=brace}

What I would like to achieve is the following (all for subfigures):

  1. the label should be \alph), e.g. a)
  2. a \subref{subfigureLabel} or \ref{subfigureLabel} should return basically the label: \alph), e.g. a)
  3. a \ref{compositeFigure} should return the prefix, the figurenumber, a space, followed by the label (including the brace), e.g. 'Figure 1.1 a)', (basically append the label of the subfigure with a space).

As you can see I solved (not quite satisfactory) 1. and 2., however I am struggling with three. First of I could not find anything like refformat, however there are good reasons for the existence of subrefformat. However I want to use \subref just for the short version (see 2.), so I can't use that. Furthermore I would like to know if there is an option to set the label and subref format with one command (I think it is reasonable and common to define them equally).

P.S.: I have seen http://tex.stackexchange.com/a/122306/19326, however it is a) for subfig and b) looks messier/more complicated than what I hope for but if that is what it takes...

share|improve this question
    
Maybe cleveref is worth a look. –  Martin Jul 29 '13 at 10:27
    
I am not sure yet. Note that I noticed two mistakes in my question and fixed them (I actually want to just ref and decide based on the label). The clevermanual states Cleveref does not modify the standard \ref or \pageref commands, so I am not sure it is the right tool for the job. I will give it a detailed look in the next day(s) and come back to this. –  ted Jul 29 '13 at 11:00
    
You just use \cref instead of \ref. This command will the decide for you based on the label what it will typeset. However it will not typeset the ) brace, because this should be used as a delimiter only. If you really need the brace you should just simply redefine \thesubfigure –  Martin Jul 29 '13 at 13:06
add comment

1 Answer

up vote 2 down vote accepted

I am not sure if this is the desired result, but this was too long for a comment. The label format for subfigures is set to simple (just the counter with no parenthesis); \thesubfigure is redefined to include the parenthesis and then \p@subfigure (the prefix used when cross-referencing subfigures) is redefined to be the representation for the figure counter followed by a non-breakable space:

\documentclass{book}
\usepackage{subcaption}
\usepackage{graphicx}

\DeclareCaptionSubType[alph]{figure}
\captionsetup[subfigure]{labelformat=simple,justification=centerlast}

\renewcommand\thesubfigure{\alph{subfigure})}
\makeatletter
\renewcommand\p@subfigure{\thefigure~}
\makeatother

\begin{document}

\chapter{Test chapter}

A reference to the figure:~\ref{fig:test}

A reference to the first subfigure:~\ref{sfig:testa}

A subreference to the first subfigure:~\subref{sfig:testa}

A reference to the second subfigure:~\ref{sfig:testb}

A subreference to the second subfigure:~\subref{sfig:testb}

\begin{figure}[!ht]
\begin{subfigure}{0.5\textwidth}
\centering
\includegraphics[height=4cm]{example-image-a}
\caption{a subfigure}
\label{sfig:testa}
\end{subfigure}%
\begin{subfigure}{0.5\textwidth}
\centering
\includegraphics[height=4cm]{example-image-b}
\caption{another subfigure}
\label{sfig:testb}
\end{subfigure}
\caption{a figure with two subfigures}
\label{fig:test}
\end{figure}

\end{document}

enter image description here

share|improve this answer
    
Much to my pleasure it works with floatrow as well. –  ted Jul 29 '13 at 22:08
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.