2

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}

3 Answers 3

3

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}
3

For sub-images I would use subfigure environment (defined in the subcaption package), delete hfill on the end of images row and remove minipage around minipages in the second figure row::

\documentclass[11pt]{article}
\usepackage[T1]{fontenc}
\usepackage[spanish]{babel}

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

\begin{document}
    \begin{figure}[htb]
\begin{subfigure}[t]{.32\textwidth}
    \includegraphics[width=\textwidth]{images/1.png}
    \caption{Image 1.}
    \label{fig:1}
\end{subfigure}
    \hfill
\begin{subfigure}[t]{.32\textwidth}
    \includegraphics[width=\textwidth]{images/1.png}
    \caption{Image 2.}
    \label{fig:2}
\end{subfigure}
    \hfill
\begin{subfigure}[t]{.32\textwidth}
    \includegraphics[width=\textwidth]{images/1.png}
    \caption{Image 3.}
    \label{fig:1}
\end{subfigure}
\caption{Title}

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

enter image description here

1

Try this code:

\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{figure}[h]
      \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{figure}

\end{document}

enter image description here

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.