3

it's my first question so I hope to present the problem correctly. I have a problem with subcaption of subfig package: the subcaption is aligned to the left and isn't as wide as the figure. I tried to simplify my document to the essential or setting the caption option with \captionsetup[subfloat]{} but it doesn't work and the result is the same. I have no idea how to make it work and I don't have much time to try other solution. I attach the simplify document:

\documentclass[12pt]{book}      
\usepackage[T1]{fontenc}                
\usepackage[utf8]{inputenc}                 
\usepackage{indentfirst}                    

\usepackage[pdftex]{graphicx}       
\usepackage{caption}                    
\captionsetup[subfloat]{}
\usepackage{float}      
\usepackage{subfig} 

                        
\begin{document}

    \begin{figure}[p]
        %   
        \subfloat[PPL dolomite smithsonite calcite]{\label{2.JPG}} \includegraphics[width=0.5\textwidth]{2.JPG}
        %   
        \subfloat[CL galena sfalertie pirite]{\label{2.JPG}} \includegraphics[width=0.5\textwidth]{SAL 102_9.JPG}
        %       
        \caption{minerals minerals minerals}
        \label{minerals}
    \end{figure}.

\end{document}
2

The syntax of \subfloat is as follows:

\subfloat[〈listentry〉][〈sub-caption〉]{〈body〉}

with

  • 〈listentry〉 being the sub caption used in the list of figures (identical to 〈sub-caption〉 if you did not specify a separate 〈listentry〉),

  • 〈sub-caption〉 being the subcaption shown above/below the image/table, and

  • 〈body〉 being the image/table itself.

Thus, a compiling MWE would look like the following (I replaced your images with example-image):

enter image description here

\documentclass[12pt]{book}      
\usepackage[T1]{fontenc}                
\usepackage[utf8]{inputenc}                 
\usepackage{indentfirst}                    

\usepackage{graphicx}       
\usepackage{caption}                    
\usepackage{float}      
\usepackage{subfig} 

                        
\begin{document}

    \begin{figure}[p]
        %   
        \subfloat[PPL dolomite smithsonite calcite]{\includegraphics[width=0.5\textwidth]{example-image}\label{1.JPG}} 
        %   
        \subfloat[CL galena sfalertie pirite]{\includegraphics[width=0.5\textwidth]{example-image}\label{2.JPG}} 
        %       
        \caption{minerals minerals minerals}
        \label{minerals}
    \end{figure}

\end{document}
| improve this answer | |
  • Thank you very much! – summy Nov 22 at 11:56
2

There is no problem if you do that with floatrow.

Unrelated: if you have a comparatively recent version of latex, you don't have to load inputenc: utf8 isnow the default.

\documentclass[12pt]{book}
\usepackage[T1]{fontenc}
\usepackage{indentfirst}
\usepackage{mwe}
\usepackage{graphicx}
\usepackage{caption, subcaption}
\usepackage{floatrow}

\begin{document}

    \begin{figure}[p]
    \centering
    \ffigbox{%
        \begin{subfloatrow}%
        \ffigbox{\caption{PPL dolomite smithsonite calcite}\label{a.JPG}}{\includegraphics[width=0.45\textwidth]{example-image-a}}
        \hfill%
        \ffigbox{\caption{CL galena sfalertie pirite}\label{b.JPG}}{\includegraphics[width=0.45\textwidth]{example-image-b}}
        \end{subfloatrow}}%
        {\caption{minerals minerals minerals}}
        \label{minerals}
    \end{figure}

\end{document} 

enter image description here

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.