LaTeX forum ⇒ Graphics, Figures & Tablessubcaption | Uppercase in References to Sub-figure Topic is solved

Information and discussion about graphics, figures & tables in LaTeX documents.
fumarat
Posts: 4
Joined: Fri Jan 11, 2013 12:33 pm

subcaption | Uppercase in References to Sub-figure

Postby fumarat » Fri Jan 11, 2013 12:42 pm

Hey guys,

I've been a frequent reader of the forum throughout my masters thesis. I found solutions to all of my problems. But now there is one, for which I can't find a solution at all. I hope you guys can help me out with that one.

I am using the hyperref package with the following setup:
  1. \usepackage[ngerman,breaklinks=true,colorlinks=false, pdfborder={0 0 0}]{hyperref}
  2. \addto\extrasngerman{%
  3. \def\subsectionautorefname{Abschnitt}%
  4. }
  5. \addto\extrasngerman{%
  6. \def\subsubsectionautorefname{Abschnitt}%
  7. }
  8. \addto\extrasngerman{%
  9. \def\tableautorefname{Tab.}%
  10. }
  11. \addto\extrasngerman{%
  12. \def\figureautorefname{Abb.}%
  13. }

I make figures with the following setup:
  1. \usepackage{graphicx}
  2. \usepackage{caption}
  3. \usepackage{subcaption}
  4. \captionsetup[figure]{format=plain,textformat=period,singlelinecheck=false,labelfont={sc,bf},skip=0.5cm,position=bottom}
  5. \captionsetup[table]{format=plain,textformat=period,singlelinecheck=false,labelfont={sc,bf},skip=0.5cm,position=top}
  6. \captionsetup[sub]{format=plain,skip=0.5ex,position=top,font+=Large,labelfont={sc,bf},labelformat=simple}

The problem: When I refer to a sub-figure with \autoref{subfigure} the result would be "Abb. 1a". But the desired result is "Abb. 1A".

Is there any way to modify the \autoref command to give the desired format?

I can't provide a MWE right now because I don't have access to the computer with my documents at the moment.

Thanks a lot in advance!
Last edited by Stefan Kottwitz on Fri Jan 11, 2013 1:13 pm, edited 1 time in total.

Tags:

User avatar
sommerfee
Posts: 498
Joined: Mon Apr 09, 2007 4:20 pm

Postby sommerfee » Fri Jan 11, 2013 10:37 pm

fumarat wrote:The problem: When I refer to a subfigure with \autoref{subfigure} the result would be "Abb. 1a". But the desired result is "Abb. 1A".

And how should the sub-captions look like? "(a)" or "(A)" or something completely different?

fumarat
Posts: 4
Joined: Fri Jan 11, 2013 12:33 pm

Postby fumarat » Fri Jan 11, 2013 10:48 pm

sommerfee wrote:And how should the sub-captions look like? "(a)" or "(A)" or something completely different?

The sub-captions of my figures are formatted like this.
  1. A B and so on, so there is figure 4 A and 4 B

For example, when I refer to figure 4A with the \autoref command, the result is "Abb. 4a". As you can see, the letter that refers to a sub-figure is written in lowercase. Also there is no space between the digit (4) and the letter (a).

What I want the \autoref command to do is "Abb. 4 A" (-> Space between digit and letter and the letter in uppercase). I hope that clarifies my problem a bit more.

User avatar
sommerfee
Posts: 498
Joined: Mon Apr 09, 2007 4:20 pm

Postby sommerfee » Fri Jan 11, 2013 11:09 pm

fumarat wrote:The subcaptions of my figures are formated like thiss.
  1. A B and so on, so there is figure 4 A and 4 B

For example, when I refer to figure 4 A with the \autoref command, the result is "Abb. 4a"

If the sub-captions are already uppercase the references should be uppercase, too. Since this is not the case in your document a MWE is mandatory to examine this problem.
fumarat wrote:Also there is no space between the digit (4) and the letter (a).

You can add a space by redefining \p@subfigure, e.g.:
  1. \makeatletter
  2. \def\p@subfigure{\thefigure~}
  3. \makeatother

fumarat
Posts: 4
Joined: Fri Jan 11, 2013 12:33 pm

Postby fumarat » Sat Jan 12, 2013 4:56 pm

Here is a MWE finally.
  1. \documentclass[11pt,twoside,openright,BCOR=12mm,DIV=13,headinclude=false,footinclude=false]{scrreprt}
  2. \raggedbottom
  3.  
  4. % Schriftarten
  5. \setkomafont{sectioning}{\normalcolor\bfseries}
  6. %\addtokomafont{subsection}{\Large}
  7. \addtokomafont{subsubsection}{\large}
  8. \addtokomafont{caption}{\small}
  9. \addtokomafont{paragraph}{\scshape}
  10. \usepackage[usenames,dvipsnames]{color}
  11.  
  12. % für Querformat
  13. \usepackage{pdflscape}
  14. \usepackage[figuresright]{rotating}
  15.  
  16. % für Buchstaben mit Kreis drumherum
  17. \usepackage{tikz}
  18.  
  19. % für Zahlen mit Kreis drumherum
  20. \usepackage{pifont}
  21.  
  22. \usepackage{mathpazo} % Palatino für Mathemodus
  23. \usepackage{setspace} % Zeilenabstand
  24. \onehalfspacing % 1,5 Zeilen
  25.  
  26. \usepackage[T1]{fontenc}
  27. \usepackage[utf8]{inputenc}
  28.  
  29. % Gliederung
  30. \setcounter{secnumdepth}{3}
  31. \setcounter{tocdepth}{3}
  32.  
  33. % Sonderzeichen
  34. \usepackage{upgreek} %für aufrechte griechische Buchstaben im Mathe-Modus
  35.  
  36. % Kopf- und Fußzeilen
  37. \usepackage[automark,komastyle]{scrpage2}
  38.  
  39. % Absätze
  40. \usepackage{parskip}
  41. % \addtolength{\parskip}{\baselineskip}
  42. \parskip 12pt plus 1pt minus 1pt
  43. \parindent 0pt
  44.  
  45. % Mathesachen
  46. \usepackage{amsmath,marvosym}
  47. % für chemische Formeln
  48. \usepackage[version=3]{mhchem}
  49.  
  50. % Sprache: Deutsch
  51. \usepackage[ngerman]{babel}
  52.  
  53. % Hyperref und Autoref-Sachen
  54. \usepackage[ngerman,pdfauthor={Maximilian Plach},pdftitle={Masterarbeit},breaklinks=true,colorlinks=false, pdfborder={0 0 0}]{hyperref}
  55. \addto\extrasngerman{%
  56. \def\subsectionautorefname{Abschnitt}%
  57. }
  58. \addto\extrasngerman{%
  59. \def\subsubsectionautorefname{Abschnitt}%
  60. }
  61. \addto\extrasngerman{%
  62. \def\tableautorefname{Tab.}%
  63. }
  64. \addto\extrasngerman{%
  65. \def\figureautorefname{Abb.}%
  66. }
  67.  
  68.  
  69. \usepackage[final]{microtype} % mikrotypographische Optimierungen
  70.  
  71. \usepackage{pdflscape} % einzelne Seiten drehen können
  72.  
  73. % Tabellen
  74. \usepackage{multirow} % Tabellen-Zellen über mehrere Zeilen
  75. \usepackage{multicol} % mehre Spalten auf eine Seite
  76. \usepackage{tabularx} % Für Tabellen mit vorgegeben Größen
  77. \usepackage{longtable} % Tabellen über mehrere Seiten
  78. \usepackage{booktabs}
  79. \usepackage{array}
  80. \usepackage{tabulary}
  81.  
  82. % Bibliographie
  83. \usepackage[numbers,comma,round,authoryear]{natbib}
  84. \usepackage{bibgerm} % Umlaute in BibTeX
  85.  
  86. % Abbildungen
  87. \usepackage{graphicx} % Bilder
  88. \usepackage{caption}
  89. \usepackage{subcaption}
  90. \captionsetup[figure]{format=plain,textformat=period,singlelinecheck=false,labelfont={sc,bf},skip=0.5cm,position=bottom}
  91. \captionsetup[table]{format=plain,textformat=period,singlelinecheck=false,labelfont={sc,bf},skip=0.5cm,position=top}
  92. \captionsetup[sub]{format=plain,skip=0.5ex,position=top,font+=Large,labelfont={sc,bf},labelformat=simple}
  93.  
  94. \graphicspath{{images/}}
  95. \DeclareGraphicsExtensions{.pdf,.png,.jpg} % bevorzuge pdf-Dateien
  96. \usepackage[all]{hypcap} % Beim Klicken auf Links zum Bild und nicht zu Caption gehen
  97.  
  98. %\newcommand{\subfigureautorefname}{\figurename} % um \autoref auch für subfigures benutzen
  99.  
  100. % Einheiten
  101. \usepackage{textcomp}
  102. \usepackage{sistyle}
  103. \SIstyle{German}
  104. \SIunitsep{\,}
  105. \newcommand*{\micro}{\ensureupmath{\mbox{\textmu}}}
  106. \newcommand*{\microL}{\ensureupmath{\mbox{\textmu L}}}
  107. \newcommand*{\microM}{\ensureupmath{\mbox{\textmu M}}}
  108.  
  109. % eigene Commands
  110. \newcolumntype{C}[1]{>{\centering\arraybackslash}m{#1}}
  111. \newcolumntype{K}[1]{>{\arraybackslash}m{#1}}
  112.  
  113. %--- circle with a letter
  114. \newcommand\kreis[1]{\ensuremath{\mathbin{\settowidth{\dimen7}{\mbox{$ \bigcirc$}}%
  115. \makebox[0pt][l]{$\bigcirc$}\makebox[\dimen7]{#1}}}}
  116.  
  117. \newcommand*\circled[1]{\tikz[baseline=(char.base)]{
  118. \node[shape=rectangle,draw,inner sep=0.5pt] (char) {#1};}}
  119.  
  120. % Formelverzeichnis
  121. \DeclareNewTOC[%
  122. indent=18pt,% kein Einzug im Verzeichnis
  123. hang=2.4em,% Einzug für den Text im Verzeichnis
  124. type=equation
  125. ]{loe}
  126.  
  127. \AtBeginDocument{%
  128. \newcaptionname{ngerman}\equationname{Formel}%
  129. \newcaptionname{ngerman}\listequationname{Formelverzeichnis}%
  130. }
  131.  
  132. % Voraussetzung für das Eintragen von Formeln ins Formelverzeichnis
  133. \makeatletter
  134. \newcommand*{\@currententry}{}
  135. % Zwei amsmath-Anweisungen ändern:
  136. \g@addto@macro\make@display@tag{\set@currententry}%
  137. \def\tagform@#1{\maketag@@@{(\ignorespaces#1\unskip\@@italiccorr)}%
  138. \set@currententry}
  139. \newcommand*{\set@currententry}{%
  140. \typeout{set current entry}%
  141. \ifx\@currententry\@empty\else
  142. \addcontentsline{loe}{equation}{\protect\numberline{\@currentlabel}%
  143. \@currententry}%
  144. \global\let\@currententry\@empty
  145. \fi
  146. }
  147. % Neue Benutzeranweisung
  148. \newcommand*{\equationentry}[1]{%
  149. \gdef\@currententry{#1}%
  150. }
  151. \makeatother
  152.  
  153. % Eigene Farben
  154. \definecolor{RegRed}{cmyk}{0,1,1,0}
  155. \definecolor{DarkGreen}{RGB}{0,102,51}
  156. \definecolor{LightGreen}{RGB}{51,204,102}
  157. \definecolor{Grau}{gray}{.80}
  158.  
  159. % Symbolpakete
  160. \usepackage{marvosym} % für Schere (mit \Rightscissors} zum Drehen \rotatebox{90}{\Rightscissors}
  161.  
  162. % Listen und Aufzählungen
  163. \usepackage{paralist} % für kompakte Listen, mit \begin{compactitem} und \item oder \begin{compactenum}[a)] und \item
  164.  
  165.  
  166. \begin{document}
  167.  
  168. \begin{figure}
  169. \centering
  170. \begin{subfigure}[t]{0.49\linewidth}
  171. \subcaption{}
  172. \rule{2cm}{2cm}
  173. \label{fig.1}
  174. \end{subfigure}
  175. \hspace{\fill}
  176. \begin{subfigure}[t]{0.49\linewidth}
  177. \subcaption{}
  178. \rule{2cm}{2cm}
  179. \label{fig.2}
  180. \end{subfigure}
  181. \captionsetup{aboveskip=0pt}
  182. \caption[Short Caption]{Long Caption}
  183. \label{figure}
  184. \end{figure}
  185.  
  186. Text Text Text Text Text Text Text Text Text Text Text Text Text \par
  187. \autoref{fig.1} \par
  188. Text Text Text Text Text Text Text Text Text Text Text Text Text \par
  189. \autoref{fig.2}
  190.  
  191. \end{document}

Thanks a lot for your patience ;)

Instead of \includegraphics I used \rule in this MWE. The result is attached.
Attachments
MWE.PNG
MWE.PNG (12.35 KiB) Viewed 8456 times

User avatar
sommerfee
Posts: 498
Joined: Mon Apr 09, 2007 4:20 pm

Postby sommerfee » Sat Jan 12, 2013 10:12 pm

The sub-caption labels were not uppercase but small caps instead which just looked like they were uppercase. Since the references are typeset in the current font (which is usually not small caps) they were lowercase.

So I changed them to uppercase. They may be too large now (since uppercase letters are larger than small caps letters) but you may correct this by changing the option "font+=Large" if desired, e.g. to "font+=large".

So here is your example document, reduced to the code that matters regarding your problem. I have commented the changes I made. If you have any questions about my changes please don't hesitate to ask.
  1. \documentclass{scrreprt}
  2.  
  3. \usepackage[ngerman]{babel}
  4.  
  5. \usepackage[ngerman]{hyperref}
  6. \addto\extrasngerman{%
  7. \def\tableautorefname{Tab.}%
  8. }
  9. \addto\extrasngerman{%
  10. \def\figureautorefname{Abb.}%
  11. }
  12.  
  13. \usepackage{caption,subcaption}
  14. % I dropped "position=bottom" resp. "position=top" here since this is controlled
  15. % by KOMA-Script and not by the caption package, so they had no effect
  16. % (but did not made any harm, so removing them was not strictly necessary).
  17. % (See caption package documentation, section "KOMA-Script" for details.)
  18. \captionsetup[figure]{format=plain,textformat=period,singlelinecheck=false,labelfont={sc,bf},skip=0.5cm}
  19. \captionsetup[table]{format=plain,textformat=period,singlelinecheck=false,labelfont={sc,bf},skip=0.5cm}
  20. \captionsetup[sub]{format=plain,skip=0.5ex,position=top,font+=Large,labelfont={sc,bf},labelformat=simple}
  21.  
  22. % Add a small space between figure and sub-figure number in references
  23. % (Usually \p@subfigure is defined as \thefigure, see subcaption package
  24. % documentation for details)
  25. \makeatletter
  26. \def\p@subfigure{\thefigure\,}
  27. \def\p@subtable{\thetable\,}
  28. \makeatother
  29.  
  30. % Use uppercase letters for sub-figure numbering (A, B, ... instead of a, b, ...)
  31. % (Per default \thesubfigure is defined as \alph{subfigure}, i.e. lowercase letters)
  32. \renewcommand\thesubfigure{\Alph{subfigure}}
  33. \renewcommand\thesubtable{\Alph{subtable}}
  34.  
  35. \begin{document}
  36.  
  37. \begin{figure}
  38. \centering
  39. \begin{subfigure}[t]{0.49\linewidth}
  40. \subcaption{}
  41. \rule{2cm}{2cm}
  42. \label{fig.1}
  43. \end{subfigure}
  44. \hspace{\fill}
  45. \begin{subfigure}[t]{0.49\linewidth}
  46. \subcaption{}
  47. \rule{2cm}{2cm}
  48. \label{fig.2}
  49. \end{subfigure}
  50. \captionsetup{aboveskip=0pt}
  51. \caption[Short Caption]{Long Caption}
  52. \label{figure}
  53. \end{figure}
  54.  
  55. Text Text Text Text Text Text Text Text Text Text Text Text Text \par
  56. \autoref{fig.1} \par
  57. Text Text Text Text Text Text Text Text Text Text Text Text Text \par
  58. \autoref{fig.2}
  59.  
  60. \end{document}

fumarat
Posts: 4
Joined: Fri Jan 11, 2013 12:33 pm

Postby fumarat » Sun Jan 13, 2013 2:56 pm

Wow, you are my hero :D

A simple and perfect solution! Plus: the small changes didn't destroy my layout!

Thank you very much.
I will mark this problem as solved.


Return to “Graphics, Figures & Tables”

Who is online

Users browsing this forum: No registered users and 8 guests