Graphics, Figures & TablesSubfigure captions not centering and getting referenced with double parentheses

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
Mate de Vita
Posts: 1
Joined: Fri Jan 13, 2023 7:20 pm

Subfigure captions not centering and getting referenced with double parentheses

Post by Mate de Vita »

I'm using my University's template to typeset my document and it's messing up some things about the subfigure captions in my document. This is a MWE .tex file that demonstrates my issue:

Code: Select all

% !TEX xelatex
\documentclass[language=english,stage=alpha]{FRIteza}
\usepackage{graphicx}

\newlength{\colwidth}
\newlength{\rowheight}

\begin{document}

\begin{figure*}
    \setlength{\colwidth}{.24\linewidth}
    \setlength{\rowheight}{.57\colwidth}
    \begin{subfigure}{\colwidth}
        \includegraphics[width=\textwidth,height=\rowheight]{example-image-a}
        \caption{Image A}
        \label{fig:a}
    \end{subfigure}\hfill%
    \begin{subfigure}{\colwidth}
        \includegraphics[width=\textwidth,height=\rowheight]{example-image-b}
        \caption{Image B}
        \label{fig:b}
    \end{subfigure}\hfill%
    \begin{subfigure}{2\colwidth}
        \includegraphics[width=\textwidth,height=\rowheight]{example-image-c}
        \caption{Image C}
        \label{fig:c}
    \end{subfigure}\hfill%
    \caption{3 sample images, specifically \subref{fig:a} an excerpt from A, \subref{fig:b} some stuff from B, and \subref{fig:c} things from C.}
    \label{fig:example}
\end{figure*}

Fig.~\ref{fig:example} shows some examples. Note the big letter C in Fig.~\ref{fig:c}.

\end{document}
I also made an Overleaf project that contains the class files and the required fonts, and can be downloaded as a zip file. It also has the correct software versions set up (TeX Live 2019 and XeLaTeX).

How it looks:
Image

How I'd like it to look:
Image

In the projects I've done so far, the subcaptions have normally been centered by default. I've also tried to center them manually using this advice:

Code: Select all

\captionsetup[subfigure]{justification=centering}
I've tried adding this line right after the \documentclass declaration, inside the figure environment, and inside the subfigure environment. None of these worked as the captions were still left-aligned.

Additionally, when I reference the captions in text, \ref references to subfigures don't include the parentheses. I.e. they are refered to as Fig. 0.1c, instead of Fig. 0.1(c). I've fixed this in another project by using the following:

Code: Select all

\usepackage{caption}
\makeatletter
\DeclareCaptionLabelFormat{mysublabelfmt}{(\alph{sub\@captype})}
\makeatother
\usepackage[labelformat=mysublabelfmt]{subcaption}
\renewcommand\thesubfigure{(\alph{subfigure})}
\renewcommand\thesubtable{(\alph{subtable})}
However, in this project now this same code gives me double parentheses around \subrefs.

The only code in the .cls I can find that alters caption positioning and reference format is this:

Code: Select all

\RequirePackage[style=base]{caption}
\DeclareCaptionLabelSeparator{br}{\par\vspace*{2\p@}}
\captionsetup{singlelinecheck=off,labelsep=br,labelfont=it,textfont={RaggedRight,scriptsize}}
% subcaptions
\RequirePackage{subcaption}
\captionsetup[sub]{subrefformat=parens}
\captionsetup[sub]{format=plain,labelformat=parens,labelsep=space,font={normalfont,scriptsize},labelfont=up,hypcap=true}
but this doesn't seem to change anything about subcaption adjustment. And as far as the issue with the referencing style, I've tried to mess around with these subrefformat, format, and labelformat properties along with the \renewcommands from the previously mentioned solution but I can't get all the references and captions to be parenthesised as shown in the image.

I've checked some other students' accepted submissions and they have centered subcaptions (though they seemingly did it by manually captioning the images in image editing software rather than in TeX), so these left-adjusted subcaptions don't seem to be a typesetting requirement, and they really make some of my figures unclear and difficult to read.

So, in short:
  1. How do I center the subfigure captions, while keeping the figure caption style as is?
  2. How do I parenthesise the \ref subfigure referencing, while keeping both \subref subfigure referencing and \ref figure referencing as is?
Last edited by Stefan Kottwitz on Sun Jan 15, 2023 2:54 am, edited 1 time in total.
Reason: % !TEX xelatex added to the code

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org
LaTeX Beginner's Guide LaTeX Cookbook LaTeX TikZ graphics TikZによるLaTeXグラフィックス
User avatar
sommerfee
Posts: 503
Joined: Mon Apr 09, 2007 4:20 pm

Subfigure captions not centering and getting referenced with double parentheses

Post by sommerfee »

The answer to question 1 depends on the documentclass, and since the Overleaf project isn't available anymore, I cannot take a look at it.

Regarding question 2: The trick is to take away the parenthesis from the subfigure label format and add it to the counter representation instead, for example:

Code: Select all

\usepackage[labelformat=simple]{subcaption}
\renewcommand\thesubfigure{(\alph{subfigure})}
Full example document:

Code: Select all

\documentclass{article}
\usepackage{graphicx}

\usepackage[labelformat=simple]{subcaption}
\renewcommand\thesubfigure{(\alph{subfigure})}

\newlength{\colwidth}
\newlength{\rowheight}

\begin{document}

\begin{figure}
    \setlength{\colwidth}{.24\linewidth}
    \setlength{\rowheight}{.57\colwidth}
    \begin{subfigure}{\colwidth}
        \includegraphics[width=\textwidth,height=\rowheight]{example-image-a}
        \caption{Image A}
        \label{fig:a}
    \end{subfigure}\hfill%
    \begin{subfigure}{\colwidth}
        \includegraphics[width=\textwidth,height=\rowheight]{example-image-b}
        \caption{Image B}
        \label{fig:b}
    \end{subfigure}\hfill%
    \begin{subfigure}{2\colwidth}
        \includegraphics[width=\textwidth,height=\rowheight]{example-image-c}
        \caption{Image C}
        \label{fig:c}
    \end{subfigure}\hfill%
    \caption{3 sample images, specifically \subref{fig:a} an excerpt from A, \subref{fig:b} some stuff from B, and \subref{fig:c} things from C.}
    \label{fig:example}
\end{figure}

Fig.~\ref{fig:example} shows some examples. Note the big letter C in Fig.~\ref{fig:c}.

\end{document}
Post Reply