我对 Latex 还不太熟悉,在并排放置图形时遇到了一些问题。我希望将第一幅图像移到文本左侧一点,将第二幅图像移到文本右侧一点,这样我就可以将它们放大而不会重叠。此外,我希望子标题相对于图形居中。所以我想问你:
- 我的代码有什么问题?
- 有没有更好的方法来实现我想要做的事情?
- 如何扩大文本和图像之间的空间?
我附上我所能做的事情。
\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}
多谢!
答案1
如果您希望图像宽度大于文本宽度,则changepage
该包可以帮助您:
\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}
答案2
如果要防止图像之间重叠,最好使用选项,width=\linewidth
而不是间接的选项scale=0.4
。(我会将宽度设置为0.48\textwidth
,而不是0.499\textwidth
...)通过这种调整,也没有必要使用\hspace*
指令。
\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}
答案3
子图只是带有标题的迷你页面。不确定为什么我需要\strut
s \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}