Figures with minipage – how to fit it to text width

floatsminipage

Below is my code which produces the following output:
enter image description here

What should I do to fit it to \textwidth?

\documentclass[11pt]{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc} % ensure your document is UTF-8
\usepackage[spanish]{babel}

\usepackage[demo]{graphicx} % demo option just for testing
\usepackage{caption}
\usepackage{subcaption}
\usepackage{float}
\usepackage[showframe]{geometry}

\begin{document}

% Begin minipage figure
\begin{figure}[htb]
    \begin{minipage}[t]{.32\textwidth}
        \centering
        \includegraphics[width=\textwidth]{images/1.png}
        \subcaption{Image 1.}\label{fig:1}
    \end{minipage}
    \hfill
    \begin{minipage}[t]{.32\textwidth}
        \centering
        \includegraphics[width=\textwidth]{images/2.png}
        \subcaption{Image 2.}\label{fig:2}
    \end{minipage}
    \hfill
    \begin{minipage}[t]{.32\textwidth}
        \centering
        \includegraphics[width=\textwidth]{images/rtk3.png}
        \subcaption{Image 3.}\label{fig:3}
    \end{minipage}  
    \hfill
    \label{fig:1-2-3}
    \caption{Title.}
\end{figure}


\begin{minipage}{\textwidth}
      \centering
      \begin{minipage}{0.475\textwidth}
          \begin{figure}[H]
              \includegraphics[width=\linewidth]{france-in-pictures-beautiful-places-to-photograph-eiffel-tower}
              \caption{This is the first figure}
          \end{figure}
      \end{minipage}
      \hfill
      \begin{minipage}{0.475\textwidth}
          \begin{figure}[H]
              \includegraphics[width=\linewidth]{france-in-pictures-beautiful-places-to-photograph-eiffel-tower}
              \caption{This is the second figure}
          \end{figure}
      \end{minipage}
        \hfill
  \end{minipage}

\end{document}

Best Answer

Try this code.

(1) remove the \hfill after the last figure, (2) put the minipages inside a figure environment in the second row, instead of the other way around, (3) put the label after the caption in the first row.

a

\documentclass[11pt]{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc} % ensure your document is UTF-8
\usepackage[spanish]{babel}

\usepackage[demo]{graphicx} % demo option just for testing
\usepackage{caption}
\usepackage{subcaption}
\usepackage{float}
\usepackage[showframe]{geometry}

\begin{document}
    
    % Begin minipage figure
    \begin{figure}[htb]
        \begin{minipage}[t]{.32\textwidth}
            \centering
            \includegraphics[width=\textwidth]{images/1.png}
            \subcaption{Image 1.}\label{fig:1}
        \end{minipage}
        \hfill
        \begin{minipage}[t]{.32\textwidth}
            \centering
            \includegraphics[width=\textwidth]{images/2.png}
            \subcaption{Image 2.}\label{fig:2}
        \end{minipage}
        \hfill
        \begin{minipage}[t]{.32\textwidth}
            \centering
            \includegraphics[width=\textwidth]{images/rtk3.png}
            \subcaption{Image 3.}\label{fig:3}
        \end{minipage}  
%       \hfill  
\label{fig:1-2-3}%changed
        \caption{Title.} %<<<<<<<<<<<<<<<
    \end{figure}
    
    \begin{figure}[htb]
%   \begin{minipage}{\textwidth}
        \centering
        \begin{minipage}{0.475\textwidth}
%           \begin{figure}[H]
                \includegraphics[width=\linewidth]{france-in-pictures-beautiful-places-to-photograph-eiffel-tower}
                \caption{This is the first figure}
%           \end{figure}
        \end{minipage}
        \hfill
        \begin{minipage}{0.475\textwidth}
%           \begin{figure}[H]
                \includegraphics[width=\linewidth]{france-in-pictures-beautiful-places-to-photograph-eiffel-tower}
                \caption{This is the second figure}
%           \end{figure}
        \end{minipage}
%       \hfill
%   \end{minipage}
    \end{figure}
    
\end{document}
Related Question