3

I'm quite new to Latex and I'm having some problems placing figures side by side. I want the first image to be shifted a bit on left side of the text as well as the second a little bit on the right, so that I can make them bigger without them overlapping. Moreover, I want sub-captions centered with respect to the graph. So I would like to ask you:

  • what is wrong in my code?
  • Are there better ways to do what I want to do?
  • How can I enlarge the space between text and images?

I attach what I was able to do.

\documentclass[a4paper,12pt]{report}

\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[greek,english]{babel}
\usepackage{graphicx}
\usepackage{caption}
\usepackage{subcaption}
\setlength{\parindent}{10pt}
\usepackage{lipsum} 
\usepackage{ae}
\usepackage{mwe}

\begin{document}

\lipsum[1-2]

\begin{figure}[h]
\centering 
\begin{subfigure}[t]{0.499\textwidth}%
\hspace{-2.5 cm}%
\includegraphics[scale=0.4]{{example-image-a}}%
\subcaption{Nel mezzo del cammin di nostra vita mi ritrovai per una selva oscura}%
\end{subfigure}%
\hfill%
\begin{subfigure}[t]{0.499\textwidth}%
\includegraphics[scale=0.4]{{example-image-a}}%
\subcaption{Quel ramo del lago di Como, che volge a mezzogiorno, tra due catene non interrotte di monti}%
\hspace{-2.5 cm}%
\end{subfigure}
\caption{Caption}
\end{figure}

\lipsum[3-4]

\end{document}

enter image description here

Thanks a lot!

1
  • Welcome to TeX.SE!
    – Mico
    Nov 28 '21 at 11:58
3

If you like to have image wider than text width, changepage package can help you:

\documentclass[a4paper,12pt]{article}
\usepackage[T1]{fontenc}
\usepackage{ae}
\usepackage[greek,english]{babel}
\usepackage{graphicx}
\usepackage[font=small, labelfont=bf]{caption}
\usepackage{subcaption}
\usepackage[strict]{changepage}
\setlength{\parindent}{10pt}

\usepackage{lipsum}

\begin{document}
\lipsum[1]
    \begin{figure}[ht]
\begin{adjustwidth}{-22mm}{-22mm}
\parbox{\linewidth}{% I don't know why is needed that caption has expected width
    \setkeys{Gin}{width=\linewidth}
\begin{subfigure}[t]{0.48\linewidth}%
\includegraphics{example-image-a}%
\subcaption{Nel mezzo del cammin di nostra vita mi ritrovai per una selva oscura}%
\end{subfigure}%
    \hfill%
\begin{subfigure}[t]{0.48\linewidth}%
\includegraphics{example-image-b}%
\subcaption{Quel ramo del lago di Como, che volge a mezzogiorno, tra due catene non interrotte di monti}%
\end{subfigure}

\caption{Caption}
}% end of parbox
\end{adjustwidth}
\end{figure}

\lipsum[2-3]
\end{document}

enter image description here

2
  • Thank you for your answer, I tried it and it works well. however is it possible to add label to each figure (subfigure)? Because I have some problems
    – user257608
    Dec 7 '21 at 8:49
  • @user257608, each subfigure has a label: (a), (b)! What you mean with add a label?
    – Zarko
    Dec 7 '21 at 9:17
2

If you want to prevent overlap between the images, it's best to use the option width=\linewidth instead of the somewhat indirect scale=0.4. (And I'd set that width to 0.48\textwidth, not 0.499\textwidth...) With this adjustment in place, it's not necessary to employ \hspace* directives either.

enter image description here

\documentclass[a4paper,12pt]{report}

\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[greek,english,italian]{babel}
\usepackage{graphicx}
\usepackage{caption}
\usepackage{subcaption}

\setlength{\parindent}{10pt}
\usepackage{lipsum} 

\begin{document}
\lipsum[1]

\begin{figure}[h]
\begin{subfigure}[t]{0.48\textwidth}
\includegraphics[width=\linewidth]{example-image-a}
\caption{Nel mezzo del cammin di nostra vita mi ritrovai per una selva oscura}
\end{subfigure}%
\hfill
\begin{subfigure}[t]{0.48\textwidth}
\includegraphics[width=\linewidth]{example-image-b}
\caption{Quel ramo del lago di Como, che volge a mezzogiorno, tra due catene non interrotte di monti}
\end{subfigure}

\caption{Caption} % overall caption
\end{figure}

\lipsum[3]
\end{document}
1
  • Thank you Mico, I tried your code but for my purposes it works better solution by zarko. Anyway thank you for your time!
    – user257608
    Dec 7 '21 at 8:47
0

A subfigure is just a minipage with captions. Not sure why I need \struts around \hfill.

\documentclass[a4paper,12pt]{report}

\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[greek,english]{babel}
\usepackage{graphicx}
\usepackage{caption}
\usepackage{subcaption}
\setlength{\parindent}{10pt}
\usepackage{lipsum} 
\usepackage{ae}
\usepackage{mwe}

\begin{document}

\lipsum[1-2]

\begin{figure}[h]
\hspace*{-2.5 cm}%
\begin{subfigure}[t]{\dimexpr 0.5\textwidth+2.5cm-0.5\columnsep}
\centering
\includegraphics[scale=0.4]{{example-image-a}}%
\caption{Nel mezzo del cammin di nostra vita mi ritrovai per una selva oscura}%
\end{subfigure}%
\strut\hfill\strut
\begin{subfigure}[t]{\dimexpr 0.5\textwidth+2.5cm-0.5\columnsep}
\centering
\includegraphics[scale=0.4]{{example-image-a}}%
\caption{Quel ramo del lago di Como, che volge a mezzogiorno, tra due catene non interrotte di monti}%
\end{subfigure}%
\hspace*{-2.5 cm}
\caption{Caption}
\end{figure}

\lipsum[3-4]

\end{document}
1
  • Hi John Kormylo, thank you for your answer. I will try as soon as possible your code!
    – user257608
    Dec 7 '21 at 8:50

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.