我试图将 4 张不同高度的照片添加到我的文档中,但它们没有对齐!我无法向上移动照片中显示为红色的照片,因此它们与其余照片对齐(代码中的第 1 页和第 3 页)。我该如何解决这个问题?
\begin{figure}
\includegraphics[width=.5\textwidth,scale=0.6,page=1]{Survey 1.pdf}\hfill%
\includegraphics[width=.5\textwidth,scale=0.6,page=3]{Survey 1.pdf}\hfill\\[\smallskipamount]%
\includegraphics[width=.5\textwidth,scale=0.6,page=2]{Survey 1.pdf}\hfill%
\includegraphics[width=.5\textwidth,scale=0.6,page=4]{Survey 1.pdf}
\caption{Some images}\label{fig:foobar}
\end{figure}
答案1
如果您提供我们可以直接编译的 MWE(最小工作示例),我们将更轻松地为您提供帮助。图像可以用 替换example-image-a
。
放置图像的一个解决方案是使用\raisebox
,或者adjustbox
提供valign
参数:
\documentclass[]{article}
\usepackage{graphicx}
\usepackage[export]{adjustbox} % provide the key valign, but I don't find it really precise compared to raisebox, not sure why
\begin{document}
Compare:\\ \includegraphics[width=3cm]{example-image-a}\includegraphics[width=5cm]{example-image-a}
With:\\
\includegraphics[valign=t,width=3cm]{example-image-a}\includegraphics[valign=t,width=5cm]{example-image-a}
Or:\\
\raisebox{-\height}{\includegraphics[valign=t,width=3cm]{example-image-a}}\raisebox{-\height}{\includegraphics[valign=t,width=5cm]{example-image-a}}
\end{document}
答案2
再举一个使用adjustbox
包的例子:
\documentclass{article}
\usepackage[export]{adjustbox} % it loads graphicx package too
\begin{document}
\begin{figure}[htb]
\setkeys{Gin}{width=.48\textwidth} % all images have equal width
\includegraphics[height=33mm, % in real document remove this option
valign=T]{example-image-a}\hfill%
\includegraphics[height=44mm, % in real document remove this option
valign=T]{example-image-b}
\medskip
\includegraphics[height=33mm, % in real document remove this option
valign=T]{example-image-a}\hfill%
\includegraphics[height=55mm, % in reall document remove this option
valign=T]{example-image-b}
\caption{Some images}
\label{fig:foobar}
\end{figure}
\end{document}
观察用于valign
键的T
选项。
答案3
(评论太长,因此作为答案发布)
scale=0.6
以下设置适合您吗?(请注意,在所有情况下我都已删除该选项。)
\documentclass[demo]{article} % remove 'demo' option in real doc.
\usepackage{graphicx}
\begin{document}
\begin{figure}[htpb]
\includegraphics[width=.49\textwidth,page=1]{Survey 1.pdf}\hfill%
\includegraphics[width=.49\textwidth,page=3]{Survey 1.pdf}
\medskip
\includegraphics[width=.49\textwidth,page=2]{Survey 1.pdf}\hfill%
\includegraphics[width=.49\textwidth,page=4]{Survey 1.pdf}
\caption{Some images}\label{fig:foobar}
\end{figure}
\end{document}