Graphics, Figures & Tablessubcaption | Uppercase in References to Sub-figure

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

subcaption | Uppercase in References to Sub-figure

Post by fumarat »

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:

Code: Select all

\usepackage[ngerman,breaklinks=true,colorlinks=false, pdfborder={0 0 0}]{hyperref}
\addto\extrasngerman{%  
  \def\subsectionautorefname{Abschnitt}%  
} 
\addto\extrasngerman{%  
  \def\subsubsectionautorefname{Abschnitt}%  
} 
\addto\extrasngerman{%  
  \def\tableautorefname{Tab.}%  
} 
\addto\extrasngerman{%  
  \def\figureautorefname{Abb.}%  
}
I make figures with the following setup:

Code: Select all

\usepackage{graphicx}
\usepackage{caption}
\usepackage{subcaption}
\captionsetup[figure]{format=plain,textformat=period,singlelinecheck=false,labelfont={sc,bf},skip=0.5cm,position=bottom}
\captionsetup[table]{format=plain,textformat=period,singlelinecheck=false,labelfont={sc,bf},skip=0.5cm,position=top}
\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.

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

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

subcaption | Uppercase in References to Sub-figure

Post by sommerfee »

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

subcaption | Uppercase in References to Sub-figure

Post by fumarat »

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.

Code: Select all

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: 503
Joined: Mon Apr 09, 2007 4:20 pm

subcaption | Uppercase in References to Sub-figure

Post by sommerfee »

fumarat wrote:The subcaptions of my figures are formated like thiss.

Code: Select all

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.:

Code: Select all

\makeatletter
  \def\p@subfigure{\thefigure~}
\makeatother
fumarat
Posts: 4
Joined: Fri Jan 11, 2013 12:33 pm

subcaption | Uppercase in References to Sub-figure

Post by fumarat »

Here is a MWE finally.

Code: Select all

\documentclass[11pt,twoside,openright,BCOR=12mm,DIV=13,headinclude=false,footinclude=false]{scrreprt}
\raggedbottom

% Schriftarten
\setkomafont{sectioning}{\normalcolor\bfseries}
%\addtokomafont{subsection}{\Large}
\addtokomafont{subsubsection}{\large}
\addtokomafont{caption}{\small}
\addtokomafont{paragraph}{\scshape}
\usepackage[usenames,dvipsnames]{color}

% für Querformat
\usepackage{pdflscape} 
\usepackage[figuresright]{rotating}

% für Buchstaben mit Kreis drumherum
\usepackage{tikz}    

% für Zahlen mit Kreis drumherum
\usepackage{pifont}

\usepackage{mathpazo} % Palatino für Mathemodus
\usepackage{setspace} % Zeilenabstand
\onehalfspacing % 1,5 Zeilen

\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}

% Gliederung
\setcounter{secnumdepth}{3}
\setcounter{tocdepth}{3}

% Sonderzeichen
\usepackage{upgreek} %für aufrechte griechische Buchstaben im Mathe-Modus

% Kopf- und Fußzeilen
\usepackage[automark,komastyle]{scrpage2}

% Absätze
\usepackage{parskip}
% \addtolength{\parskip}{\baselineskip}
\parskip 12pt plus 1pt minus 1pt 
\parindent 0pt  

% Mathesachen
\usepackage{amsmath,marvosym}
% für chemische Formeln
\usepackage[version=3]{mhchem}

% Sprache: Deutsch
\usepackage[ngerman]{babel}  

% Hyperref und Autoref-Sachen
\usepackage[ngerman,pdfauthor={Maximilian Plach},pdftitle={Masterarbeit},breaklinks=true,colorlinks=false, pdfborder={0 0 0}]{hyperref}
\addto\extrasngerman{%  
  \def\subsectionautorefname{Abschnitt}%  
} 
\addto\extrasngerman{%  
  \def\subsubsectionautorefname{Abschnitt}%  
} 
\addto\extrasngerman{%  
  \def\tableautorefname{Tab.}%  
} 
\addto\extrasngerman{%  
  \def\figureautorefname{Abb.}%  
} 


\usepackage[final]{microtype} % mikrotypographische Optimierungen

\usepackage{pdflscape} % einzelne Seiten drehen können

% Tabellen
\usepackage{multirow} % Tabellen-Zellen über mehrere Zeilen
\usepackage{multicol} % mehre Spalten auf eine Seite
\usepackage{tabularx} % Für Tabellen mit vorgegeben Größen
\usepackage{longtable} % Tabellen über mehrere Seiten
\usepackage{booktabs}
\usepackage{array}
\usepackage{tabulary}

%  Bibliographie
\usepackage[numbers,comma,round,authoryear]{natbib}
\usepackage{bibgerm} % Umlaute in BibTeX

% Abbildungen
\usepackage{graphicx} % Bilder
\usepackage{caption}
\usepackage{subcaption}
\captionsetup[figure]{format=plain,textformat=period,singlelinecheck=false,labelfont={sc,bf},skip=0.5cm,position=bottom}
\captionsetup[table]{format=plain,textformat=period,singlelinecheck=false,labelfont={sc,bf},skip=0.5cm,position=top}
\captionsetup[sub]{format=plain,skip=0.5ex,position=top,font+=Large,labelfont={sc,bf},labelformat=simple}

\graphicspath{{images/}}
\DeclareGraphicsExtensions{.pdf,.png,.jpg} % bevorzuge pdf-Dateien
\usepackage[all]{hypcap} % Beim Klicken auf Links zum Bild und nicht zu Caption gehen

%\newcommand{\subfigureautorefname}{\figurename} % um \autoref auch für subfigures benutzen

% Einheiten
\usepackage{textcomp}
\usepackage{sistyle}
\SIstyle{German}
\SIunitsep{\,}
\newcommand*{\micro}{\ensureupmath{\mbox{\textmu}}}
\newcommand*{\microL}{\ensureupmath{\mbox{\textmu L}}}
\newcommand*{\microM}{\ensureupmath{\mbox{\textmu M}}}

% eigene Commands
\newcolumntype{C}[1]{>{\centering\arraybackslash}m{#1}}
\newcolumntype{K}[1]{>{\arraybackslash}m{#1}}

%--- circle with a letter
\newcommand\kreis[1]{\ensuremath{\mathbin{\settowidth{\dimen7}{\mbox{$ \bigcirc$}}%
\makebox[0pt][l]{$\bigcirc$}\makebox[\dimen7]{#1}}}}

\newcommand*\circled[1]{\tikz[baseline=(char.base)]{
            \node[shape=rectangle,draw,inner sep=0.5pt] (char) {#1};}}

% Formelverzeichnis
\DeclareNewTOC[%
  indent=18pt,% kein Einzug im Verzeichnis
  hang=2.4em,% Einzug für den Text im Verzeichnis
  type=equation
]{loe}

\AtBeginDocument{%
  \newcaptionname{ngerman}\equationname{Formel}%
  \newcaptionname{ngerman}\listequationname{Formelverzeichnis}%
} 

% Voraussetzung für das Eintragen von Formeln ins Formelverzeichnis
\makeatletter
\newcommand*{\@currententry}{}
% Zwei amsmath-Anweisungen ändern:
\g@addto@macro\make@display@tag{\set@currententry}%
\def\tagform@#1{\maketag@@@{(\ignorespaces#1\unskip\@@italiccorr)}%
  \set@currententry}
\newcommand*{\set@currententry}{%
  \typeout{set current entry}%
  \ifx\@currententry\@empty\else
    \addcontentsline{loe}{equation}{\protect\numberline{\@currentlabel}%
      \@currententry}%
    \global\let\@currententry\@empty
  \fi
}
% Neue Benutzeranweisung
\newcommand*{\equationentry}[1]{%
  \gdef\@currententry{#1}%
}
\makeatother 

% Eigene Farben
\definecolor{RegRed}{cmyk}{0,1,1,0}
\definecolor{DarkGreen}{RGB}{0,102,51}
\definecolor{LightGreen}{RGB}{51,204,102}
\definecolor{Grau}{gray}{.80}

% Symbolpakete
\usepackage{marvosym} % für Schere (mit \Rightscissors} zum Drehen \rotatebox{90}{\Rightscissors} 

% Listen und Aufzählungen
\usepackage{paralist}	% für kompakte Listen, mit \begin{compactitem} und \item oder \begin{compactenum}[a)] und \item


\begin{document}

\begin{figure}
\centering
	\begin{subfigure}[t]{0.49\linewidth}
		\subcaption{}
		\rule{2cm}{2cm}
		\label{fig.1}
	\end{subfigure}
	\hspace{\fill}
	\begin{subfigure}[t]{0.49\linewidth}
		\subcaption{}
		\rule{2cm}{2cm}
		\label{fig.2}
	\end{subfigure}
\captionsetup{aboveskip=0pt}
\caption[Short Caption]{Long Caption}
\label{figure}
\end{figure}

Text Text Text Text Text Text Text Text Text Text Text Text Text \par
\autoref{fig.1} \par
Text Text Text Text Text Text Text Text Text Text Text Text Text  \par
\autoref{fig.2}

\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 15464 times
User avatar
sommerfee
Posts: 503
Joined: Mon Apr 09, 2007 4:20 pm

subcaption | Uppercase in References to Sub-figure

Post by sommerfee »

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.

Code: Select all

\documentclass{scrreprt}

\usepackage[ngerman]{babel}  

\usepackage[ngerman]{hyperref}
\addto\extrasngerman{%
  \def\tableautorefname{Tab.}%
}
\addto\extrasngerman{%
  \def\figureautorefname{Abb.}%
}

\usepackage{caption,subcaption}
% I dropped "position=bottom" resp. "position=top" here since this is controlled
% by KOMA-Script and not by the caption package, so they had no effect
% (but did not made any harm, so removing them was not strictly necessary).
% (See caption package documentation, section "KOMA-Script" for details.)
\captionsetup[figure]{format=plain,textformat=period,singlelinecheck=false,labelfont={sc,bf},skip=0.5cm}
\captionsetup[table]{format=plain,textformat=period,singlelinecheck=false,labelfont={sc,bf},skip=0.5cm}
\captionsetup[sub]{format=plain,skip=0.5ex,position=top,font+=Large,labelfont={sc,bf},labelformat=simple}

% Add a small space between figure and sub-figure number in references
% (Usually \p@subfigure is defined as \thefigure, see subcaption package
% documentation for details)
\makeatletter
  \def\p@subfigure{\thefigure\,}
  \def\p@subtable{\thetable\,}
\makeatother

% Use uppercase letters for sub-figure numbering (A, B, ... instead of a, b, ...)
% (Per default \thesubfigure is defined as \alph{subfigure}, i.e. lowercase letters)
\renewcommand\thesubfigure{\Alph{subfigure}}
\renewcommand\thesubtable{\Alph{subtable}}

\begin{document}

\begin{figure}
\centering
        \begin{subfigure}[t]{0.49\linewidth}
                \subcaption{}
                \rule{2cm}{2cm}
                \label{fig.1}
        \end{subfigure}
        \hspace{\fill}
        \begin{subfigure}[t]{0.49\linewidth}
                \subcaption{}
                \rule{2cm}{2cm}
                \label{fig.2}
        \end{subfigure}
\captionsetup{aboveskip=0pt}
\caption[Short Caption]{Long Caption}
\label{figure}
\end{figure}

Text Text Text Text Text Text Text Text Text Text Text Text Text \par
\autoref{fig.1} \par
Text Text Text Text Text Text Text Text Text Text Text Text Text  \par
\autoref{fig.2}

\end{document}
fumarat
Posts: 4
Joined: Fri Jan 11, 2013 12:33 pm

Re: subcaption | Uppercase in References to Sub-figure

Post by fumarat »

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.
Post Reply