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'm preparing a text in russian with pdflatex. According to standard appendices must be numbered with russian uppercase letters.

But I've found that if subfloats used in appedix, the hyperref produces error on second pdflatex pass.

! Undefined control sequence.
<argument> subfigure.\T 
                        2A\CYRA .1.1

Here is code to reproduce the error:

\documentclass[a4paper]{book}
\usepackage[utf8]{inputenc}
\usepackage[russian]{babel}
\usepackage[T2A]{fontenc}
\usepackage{graphicx}
\usepackage[config,font=small,labelsep=period]{caption,subfig}
\usepackage[unicode]{hyperref}

%use russian alphabet for subfigure counter 
\makeatletter
  \def\thesubfigure{\textit{\asbuk{subfigure}}}
  \providecommand\thefigsubsep{,~}
  \def\p@subfigure{\@nameuse{thefigure}\thefigsubsep}
\makeatother

\begin{document}

\chapter{Sample Chapter}

\appendix
%use russian alphabet for appendix counter
\makeatletter
  \gdef\thechapter{\@Asbuk\c@chapter}
\makeatother

\chapter{Sample Appendix}

Reference \ref{fig_images}, also \ref{fig_image1} and \ref{fig_image2}.

\begin{figure}
  \centering
  \subfloat[][]{\label{fig_image1}\includegraphics[width=0.15\linewidth]{image1}}
  \hspace{0.15\linewidth}
  \subfloat[][]{\label{fig_image2}\includegraphics[width=0.15\linewidth]{image2}}
  \caption[]{\label{fig_images}
    Images:
    \subref{fig_image1}~---~first;
    \subref{fig_image2}~---~second;
  }
\end{figure}

\end{document}

Is there any workaround to make it works? Or maybe any alternatives for subfig package?

share|improve this question

1 Answer 1

up vote 7 down vote accepted

The subfig package is known to have problems with hyperref. You could give my subcaption package a try instead:


\documentclass[a4paper]{book}
\usepackage[utf8]{inputenc}
\usepackage[russian]{babel}
\usepackage[T2A]{fontenc}
\usepackage[demo]{graphicx}
\usepackage[config,font=small,labelsep=period]{caption}
\usepackage{subcaption}
\usepackage[unicode]{hyperref}

%use russian alphabet for subfigure counter 
\makeatletter
  \def\thesubfigure{\textit{\asbuk{subfigure}}}
  \providecommand\thefigsubsep{,~}
  \def\p@subfigure{\@nameuse{thefigure}\thefigsubsep}
\makeatother

\begin{document}

\chapter{Sample Chapter}

\appendix
%use russian alphabet for appendix counter
\makeatletter
  \gdef\thechapter{\@Asbuk\c@chapter}
\makeatother

\chapter{Sample Appendix}

Reference \ref{fig_images}, also \ref{fig_image1} and \ref{fig_image2}.

\begin{figure}
  \centering
  \subcaptionbox{\label{fig_image1}}{\includegraphics[width=0.15\linewidth]{image1}}
  \hspace{0.15\linewidth}
  \subcaptionbox{\label{fig_image2}}{\includegraphics[width=0.15\linewidth]{image2}}
  \caption[]{\label{fig_images}
    Images:
    \subref{fig_image1}~---~first;
    \subref{fig_image2}~---~second;
  }
\end{figure}

\end{document}

(I'm sorry for the shameless self-advertisement, but the problems of subfig with hyperref were one of the many reasons why I wrote the subcaption package.)

Addendum:

As opposite to the subfig package the subcaption package will only typeout the value of \thesubfigure resp. \thesubtable as reference since this is the behaviour of all other references as well, e.g. references to figures or sections. So if one want to have the parenthesis (or other decorative elements) in references, one have to add them there and remove them from the label format (so they will not appear twice there), e.g. by using the option labelformat=simple. For example:


\documentclass[a4paper]{book}
\usepackage[utf8]{inputenc}
\usepackage[russian]{babel}
\usepackage[T2A]{fontenc}
\usepackage[demo]{graphicx}
\usepackage[config,font=small,labelsep=period]{caption}
\usepackage[labelformat=simple]{subcaption}
\usepackage[unicode]{hyperref}

%use russian alphabet for subfigure counter 
\makeatletter
  \def\thesubfigure{(\textit{\asbuk{subfigure}})}
  \providecommand\thefigsubsep{,~}
  \def\p@subfigure{\@nameuse{thefigure}\thefigsubsep}
\makeatother

\begin{document}

\chapter{Sample Chapter}

\appendix
%use russian alphabet for appendix counter
\makeatletter
  \gdef\thechapter{\@Asbuk\c@chapter}
\makeatother

\chapter{Sample Appendix}

Reference \ref{fig_images}, also \ref{fig_image1} and \ref{fig_image2}.

\begin{figure}
  \centering
  \subcaptionbox{\label{fig_image1}}{\includegraphics[width=0.15\linewidth]{image1}}
  \hspace{0.15\linewidth}
  \subcaptionbox{\label{fig_image2}}{\includegraphics[width=0.15\linewidth]{image2}}
  \caption[]{\label{fig_images}
    Images:
    \subref{fig_image1}~---~first;
    \subref{fig_image2}~---~second;
  }
\end{figure}

\end{document}

2nd Addendum (updated on 2011/08/19):

The subcaption package does support different look & feel for references and sub-references since version 1.1 from 2011/08/18, using the new option "subrefformat=". For example:


\documentclass[a4paper]{book}
\usepackage[utf8]{inputenc}
\usepackage[russian]{babel}
\usepackage[T2A]{fontenc}
\usepackage[demo]{graphicx}
\usepackage[config,font=small,labelsep=period]{caption}
\usepackage[subrefformat=parens]{subcaption}
\usepackage[unicode]{hyperref}

%use russian alphabet for subfigure counter 
\makeatletter
  \def\thesubfigure{\textit{\asbuk{subfigure}}}
  \providecommand\thefigsubsep{,~}
  \def\p@subfigure{\@nameuse{thefigure}\thefigsubsep}
\makeatother

\begin{document}

\chapter{Sample Chapter}

\appendix
%use russian alphabet for appendix counter
\makeatletter
  \gdef\thechapter{\@Asbuk\c@chapter}
\makeatother

\chapter{Sample Appendix}

Reference \ref{fig_images}, also \ref{fig_image1} and \ref{fig_image2}.

\begin{figure}
  \centering
  \subcaptionbox{\label{fig_image1}}{\includegraphics[width=0.15\linewidth]{image1}}
  \hspace{0.15\linewidth}
  \subcaptionbox{\label{fig_image2}}{\includegraphics[width=0.15\linewidth]{image2}}
  \caption[]{\label{fig_images}
    Images:
    \subref{fig_image1}~---~first;
    \subref*{fig_image2}~---~second;
  }
\end{figure}

\end{document}
share|improve this answer
    
Thanks Axel! Your solution looks good.Just one small thing, how can to make subrefs to be included in parenthesis? E.g. (a) - first, instead a - first. –  TheBug Aug 12 '11 at 18:44
    
As opposite to the subfig package the subcaption package always gives you \thesubfigure resp. \thesubtable as reference. So if you want the parenthesis in your references, too, one have to add them there and to remove them from the caption label so they will not appear twice in the figure. In detail one have to load the subcaption package with the option labelsep=simple and to add the parenthesis to \thesubfigure. I will add this as 2nd solution right now. –  Axel Sommerfeldt Aug 12 '11 at 19:15
    
Just added an addendum to my answer. –  Axel Sommerfeldt Aug 12 '11 at 19:24
    
Thanks! Yes, your second solution do the trick for \subref, but it also it leads to parenthesis in \ref output, e.g. \ref{fig_image1} outputs A.1, (a), but A.1, a expected. –  TheBug Aug 12 '11 at 19:59
2  
subcaption v1.1 is available on CTAN right now (and hopefully soon as TeXlive and MikTeX update). It supports the option subrefformat=..., so patching \subref is not necessary anymore. Will update my answer right now... (Furthermore I have extended the subcaption package documentation regarding references.) –  Axel Sommerfeldt Aug 19 '11 at 19:47

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.