latexfiguresubfigurefigcaptionsubcaption

Figure caption aligns with center of page, but not with center of Figure


This is what it looks like

Hey People,

so I've been through every forum entry I could find about this, but I can't solve this Problem: If I include multiple figures via subfigures, the centered captions hinder the figures from being side by side. I can't find a way to align my captions with the figures, rather than the page.

So far I've tried simply using two figures instead of one including subfigures. I've tried \captionsetup{width=0.33\linewidth, justification=justified,singlelinecheck=false} but the caption wont budge.

\renewcommand{\captionfont}{\small\itshape} 
\renewcommand{\figurename}{\textbf{Abb.}}   
\renewcommand{\tablename}{\textbf{Tab.}}    
\begin{figure}[H]
    \begin{subfigure}{\includegraphics[width=0.33\textwidth]{img/Filter_Vorlage.JPG}}
        \captionsetup{width=0.33\linewidth, format=hang}
        \caption{Ausgangsbild vor Maximum}
    \end{subfigure}
    \begin{subfigure}{\includegraphics[width=0.33\textwidth]{img/Filter_Max5x5.JPG}}
        \captionsetup{width=0.33\linewidth, format=hang}
        \caption{5x5 Maximum Filter angewendet}
    \end{subfigure}\hfill 
    \end{figure}

Here is a minimum working example:

\documentclass{article}

\usepackage{graphicx} 
\usepackage{float}
\usepackage{subfigure}
\usepackage{caption}
\renewcommand{\captionfont} {\small\itshape}    
\renewcommand{\figurename}  {\textbf{Abb.}} 
\renewcommand{\tablename}   {\textbf{Tab.}}


\title{StackOverflowExpl}
\author{me}
\date{September 2023}

\begin{document}

\section{FigureTest}
\begin{figure}[H]
    \begin{subfigure}{\includegraphics[width=0.33\textwidth]{img/Filter_Vorlage.JPG}}
        \captionsetup{width=0.33\linewidth, format=hang}
        \caption{Ausgangsbild vor Maximum}
    \end{subfigure}
    \begin{subfigure}{\includegraphics[width=0.33\textwidth]{img/Filter_Max5x5.JPG}}
        \captionsetup{width=0.33\linewidth, format=hang}
        \caption{5x5 Maximum Filter angewendet}
    \end{subfigure}\hfill 
    \end{figure} 

\end{document}

Solution

  • The syntax of the subfigure package for a subfigure is

    \subfigure[⟨list entry⟩][⟨subcaption⟩]{⟨figure⟩}
    

    This means while your code compiles more or less by accident, you aren't actually using any subcaption or anything other useful from it. So an easy solution to centre the normal caption with the image is using a minipage instead:

    \documentclass{article}
    
    \usepackage{graphicx} 
    \usepackage{float}
    \usepackage{subfigure}
    \usepackage{caption}
    \renewcommand{\captionfont} {\small\itshape}    
    \renewcommand{\figurename}  {\textbf{Abb.}} 
    \renewcommand{\tablename}   {\textbf{Tab.}}
    
    
    \title{StackOverflowExpl}
    \author{me}
    \date{September 2023}
    
    \begin{document}
    
    \section{FigureTest}
    \begin{figure}[H]
        \begin{minipage}{.33\textwidth}
                \includegraphics[width=\textwidth]{example-image-duck}
                \captionsetup{width=\linewidth, format=hang}
                \caption{Ausgangsbild vor Maximum}
        \end{minipage}
    
        \begin{minipage}{.33\textwidth}
                \includegraphics[width=\textwidth]{example-image-duck}
                \captionsetup{width=\linewidth, format=hang}
                \caption{Ausgangsbild vor Maximum}
        \end{minipage}
        \end{figure}
    
    \end{document}
    

    enter image description here