7

I've just read questions:

But i still haven't found answer.

Minimal example:

\documentclass{article}
\usepackage{caption}
\usepackage{subfig}
\usepackage{hyperref}

\begin{document}
\begin{figure}
 \centering
  \subfloat[subfigure A]{\rule{100pt}{50pt}
   \label{fig:subfig-a}
  }
  \subfloat[subfigure B]{\rule{100pt}{50pt}
   \label{fig:subfig-b}
  }
  \subfloat[subfigure C]{\rule{100pt}{50pt}
   \label{fig:subfig-c}
  }
 \caption{Subfigures:}
 \label{fig:figures}
\end{figure}

See Figures~\ref{fig:subfig-a}, \ref{fig:subfig-b} and~\ref{fig:subfig-c}.
\end{document}

Output looks like: default captions

What i need:

  1. Subcaptions should be a), b), c) without caption text instead of (a), (b) and (c) with caption text.
  2. Refs to subfigures should be 1,\,a instead 1a.
  3. Figure caption should consist of prefix (Fig.~1.), separation space, general caption (Subfigures:) and sub-captions of subfigures (for example, (a) --- subfigure A; (b) --- subfigure B; (c) --- subfigure C).

What i tried:

Set caption

\captionsetup[figure]{labelsep=period,justification=centering,singlelinecheck=off}

Set ref format

\makeatletter
\def\thesubfigure{\textit{\alph{subfigure}}}
\providecommand\thefigsubsep{,\,}
\def\p@subfigure{\@nameuse{thefigure}\thefigsubsep}
\makeatother

So i've got:

\documentclass{article}
\usepackage{caption}
\usepackage{subfig}
\usepackage{hyperref}

\captionsetup[figure]{labelsep=period,justification=centering,singlelinecheck=off}

\makeatletter
\def\thesubfigure{\textit{\alph{subfigure}}}
\providecommand\thefigsubsep{,\,}
\def\p@subfigure{\@nameuse{thefigure}\thefigsubsep}
\makeatother

\begin{document}
\begin{figure}
 \centering
  \subfloat[subfigure A]{\rule{100pt}{50pt}
   \label{fig:subfig-a}
  }
  \subfloat[subfigure B]{\rule{100pt}{50pt}
   \label{fig:subfig-b}
  }
  \subfloat[subfigure C]{\rule{100pt}{50pt}
   \label{fig:subfig-c}
  }
 \caption{Subfigures:}
 \label{fig:figures}
\end{figure}

See Figures~\ref{fig:subfig-a}, \ref{fig:subfig-b} and~\ref{fig:subfig-c}.
\end{document}

It looks like that: custom captions

It is still needed to correct format of sub-captions and main caption.

Also, why there are different spaces between subfigures?

1 Answer 1

4

I don't think using three different formats for the numbering of subfigures is good. Anyway, here it is:

\documentclass{article}
\usepackage{caption}
\captionsetup[figure]{labelsep=period,justification=centering,singlelinecheck=off}
\DeclareCaptionLabelFormat{rightparen}{#2)}
\usepackage{subfig}
\captionsetup[subfloat]{labelformat=rightparen}
\showcaptionsetup[uniq]{subfloat}
\usepackage{xparse}

\ExplSyntaxOn
\seq_new:N \g_akj_subfloat_seq
\NewDocumentCommand{\xsubfloat}{ m m }
 {
  \akj_subfloat:nn { #1 } { #2 }
 }
\NewDocumentCommand{\makexcaption}{o}
 {
  \caption{\IfNoValueF{#1}{#1~}Subfigures:~%
  \seq_use:Nnnn \g_akj_subfloat_seq {;~} {;~} {;~}}
 }
\cs_new_protected:Npn \akj_subfloat:nn #1 #2
 {
  % initialize
  \int_compare:nT { \value{subfigure} = 0 }
   { \seq_gclear:N \g_akj_subfloat_seq }
  % do the subfloat
  \subfloat[]{#2}
  % store the subcaption
  \seq_gput_right:Nx \g_akj_subfloat_seq { (\exp_not:N\textit{\alph{subfigure}}) ~ \exp_not:n { #1 } }
 }
\ExplSyntaxOff
\renewcommand{\thesubfigure}{\textit{\alph{subfigure}}}
\makeatletter
\def\p@subfigure{\thefigure\,}
\makeatother

\begin{document}
\begin{figure}
\centering
\xsubfloat{subfigure A}{%
  \rule{100pt}{50pt}%
  \label{fig:subfig-a}%
}
\xsubfloat{subfigure B}{%
  \rule{100pt}{50pt}%
  \label{fig:subfig-b}%
}
\xsubfloat{subfigure C}{%
  \rule{100pt}{50pt}%
  \label{fig:subfig-c}%
}
\makexcaption\label{fig:figures}
\end{figure}

See Figures~\ref{fig:subfig-a}, \ref{fig:subfig-b} and~\ref{fig:subfig-c}.
\end{document}

The \makexcaption command has also an optional argument for text going before the list of subcaptions, so

\makexcaption[Some text.]

would produce

Figure 1. Some text. Subfigures: (a) subfigure A; (b) subfigure B; (c) subfigure C

Beware of unprotected end-of-lines in the arguments of \subfloat, that are the cause of your spurious spaces.

enter image description here

6
  • I have just tried the code, written by @egreg. My pdfLaTeX (3.1415926-1.40.10) report some errors, for example ! Undefined control sequence. \akj_subfloat:nn #1#2->\int_compare:nT {\value{subfigure}=0}{\seq_gclear:N ... l.43 }
    – akj
    Jul 4, 2013 at 8:19
  • @akj Update your TeX distribution; you surely have an old version of expl3
    – egreg
    Jul 4, 2013 at 8:34
  • So, i tried to compile eample with pdfTeX(3.1415926-2.4-1.40.13, LaTeX2e 2011/06/27). It also reports errors: ! Undefined control sequence. <argument> ...ome text }Subfigures: \seq_use:Nnnn \g_akj_subfloat_seq {; }{;... l.53 \makexcaption[Some text] \label{fig:figures}. Did i need even newer version (texlive 2013)? Also, there are other errors like ! Undefined control sequence. <argument> \LaTeX3 error: A sequence was misused. l.53 \makexcaption[Some text] \label{fig:figures}
    – akj
    Jul 4, 2013 at 18:31
  • Also, writelatex.com compiled example well.
    – akj
    Jul 4, 2013 at 19:12
  • 1
    @akj TeX Live 2011 is really too old.
    – egreg
    Jul 4, 2013 at 19:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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