Graphics, Figures & TablesProblem with subfloat captions on one line under figures

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
User avatar
Cham
Posts: 937
Joined: Sat Apr 02, 2011 4:06 pm

Problem with subfloat captions on one line under figures

Post by Cham »

I'm having a problem with the subcaptions under two figures, which should stay on a single line. Here's a MWE to show the problem. How to fix this code, so the subcaptions stay on a single centered line under their figure ?

Code: Select all

\documentclass[10pt,oneside]{scrartcl}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[french]{babel}
\usepackage{microtype}
\usepackage[left=0.75in,right=0.75in,top=0.5in,bottom=0.5in,includehead,includefoot]{geometry}
\usepackage{graphicx}
\usepackage{here}
\usepackage{subfig}
\captionsetup{figurename=Figure,margin=1cm,format=hang,font=small,format=plain,labelfont={bf,up},textfont={it}}
\captionsetup[subfigure]{margin=0cm,font=small,format=plain,labelfont={bf,up},textfont={up}}

\begin{document}

Blabla bla :

\bigskip

	\begin{figure}[H]
		\centering
		\subfloat[Le multimetre Fluke.]{\includegraphics[width=3cm]{pict1.png}}
		\qquad\qquad\qquad
		\subfloat[Le multimetre Agilent.]{\includegraphics[width=3cm]{pict2.png}}
		\caption{Bla blabla bla bla.}
	\end{figure}

\end{document}
Here's a preview, with the problem exposed in red :
subloats.jpg
subloats.jpg (17.4 KiB) Viewed 12041 times

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org
TikZ book
User avatar
Johannes_B
Site Moderator
Posts: 4182
Joined: Thu Nov 01, 2012 4:08 pm

Problem with subfloat captions on one line under figures

Post by Johannes_B »

There simply isn't enough room for the caption in one single line. Personally, i prefer package subcaption:

Code: Select all

\documentclass[10pt,oneside]{scrartcl}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[french]{babel}
\usepackage{microtype}
\usepackage[left=0.75in,right=0.75in,top=0.5in,bottom=0.5in,includehead,includefoot]{geometry}
\usepackage{graphicx}
%\usepackage{here}
\usepackage{subcaption}
\captionsetup{figurename=Figure,margin=1cm,format=hang,font=small,format=plain,labelfont={bf,up},textfont={it}}
\captionsetup[subfigure]{margin=0cm,font=small,format=plain,labelfont={bf,up},textfont={up}}

\begin{document}

Blabla bla :

\bigskip

\begin{figure}%[H]% if you need H, better not use a float after all
\centering
\subcaptionbox{Le multimetre Fluke.}{\includegraphics[width=3cm]{example-image-a.png}}
\qquad\qquad\qquad
\subcaptionbox{Le multimetre Agilent.}{\includegraphics[width=3.66cm]{example-image-b.png}}
\qquad\qquad\qquad
\subcaptionbox{Le multimetre Agilent.}[3.7cm][c]{\includegraphics[width=3cm]{example-image-b.png}}
\caption{Bla blabla bla bla.}
\end{figure}

\end{document}
The smart way: Calm down and take a deep breath, read posts and provided links attentively, try to understand and ask if necessary.
User avatar
Cham
Posts: 937
Joined: Sat Apr 02, 2011 4:06 pm

Problem with subfloat captions on one line under figures

Post by Cham »

Ah, ok, I see.

But is there a way to fix the code I've posted, without changing the package ?
User avatar
Johannes_B
Site Moderator
Posts: 4182
Joined: Thu Nov 01, 2012 4:08 pm

Problem with subfloat captions on one line under figures

Post by Johannes_B »

Code: Select all

\subfloat[Le multimetre Fluke.]{\quad\includegraphics[width=3cm]{pict1.png}\quad}
The smart way: Calm down and take a deep breath, read posts and provided links attentively, try to understand and ask if necessary.
User avatar
Cham
Posts: 937
Joined: Sat Apr 02, 2011 4:06 pm

Problem with subfloat captions on one line under figures

Post by Cham »

Thanks for the trick. I'll try this, but the other solution appears to work too.
thomasb
Posts: 134
Joined: Thu Aug 03, 2017 10:54 am

Problem with subfloat captions on one line under figures

Post by thomasb »

:lol:
  • Code: Select all

    \documentclass[10pt,oneside]{scrartcl}
    \usepackage[T1]{fontenc}
    \usepackage[utf8]{inputenc}
    \usepackage[french]{babel}
    \usepackage{microtype}
    \usepackage[left=0.75in,right=0.75in,top=0.5in,bottom=0.5in,
      includehead,includefoot]{geometry}
    \usepackage{graphicx}
    \usepackage{here}
    \usepackage{subfig}
    \captionsetup{figurename=Figure,margin=1cm,format=hang,font=small,
      format=plain,labelfont={bf,up},textfont={it}}
    \captionsetup[subfigure]{margin=0cm,font=small,format=plain,
      labelfont={bf,up},textfont={up}}
    \begin{document}
    Blabla bla :
    \bigskip
    \begin{figure}[H]
      \centering
      \subfloat[Le multimetre \hspace{-1cm} Fluke.] % -joke-
        {\includegraphics[width=3cm]{pict1.png}}
      \qquad\qquad\qquad
      \subfloat[Le multimetre Agilent.]
        {\includegraphics[width=3cm]{pict2.png}}
      \caption{Bla blabla bla bla.}
    \end{figure}
    \end{document}
Post Reply