在这个代码示例中,我怎样才能强制标题与其上方图像的左角对齐并且不比图像宽?
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{graphicx}
\usepackage{caption} % for source
\usepackage{float}
\usepackage[export]{adjustbox} % valign
\newcommand{\imagesource}[1]{{\scriptsize Source: #1}}
\usepackage[export]{adjustbox}
\begin{document}
\begin{figure}[H]
\centering
\begin{minipage}[t]{.475\textwidth} % [t][][b]
\begin{tabular}[t]{ @{} r @{} }
\includegraphics[width = .9\linewidth,valign=t]{example-image} \\
\imagesource{(EU 2020)}
\end{tabular}
\end{minipage}\hfill
\begin{minipage}[t]{.475\textwidth}
\begin{tabular}[t]{ @{} r @{} }
\includegraphics[width = .7\linewidth,valign=t]{example-image} \\
\imagesource{(IEA 2019)}
\end{tabular}
\end{minipage}
\begin{minipage}[t]{.475\textwidth}
\caption{This is a caption for the first image.}\label{fig:image1}
\end{minipage}\hfill
\begin{minipage}[t]{.475\textwidth}
\caption{This is a caption for the second image.}\label{fig:image2}
\end{minipage}
\end{figure}
\end{document}
答案1
像这样?
使用 oftabular
代替minipage
s:
\documentclass{article}
\usepackage{graphicx}
\usepackage{caption} % for source
\usepackage[export]{adjustbox} % valign
\newcommand{\imagesource}[1]{{\smallskip\hfill\scriptsize Source: #1}}
\begin{document}
\begin{figure}[ht]
\centering
\setkeys{Gin}{width=\linewidth}
\begin{tabular}{p{0.45\linewidth} p{0.34\linewidth}}
\includegraphics[valign=t]{example-image}
\imagesource{(EU 2020)}
&
\includegraphics[valign=t]{example-image}
\imagesource{(IEA 2019)} \\
\caption{This is a caption for the first image.}
\label{fig:image1}
& \caption{This is a caption for the second image.}
\label{fig:image2}
\end{tabular}
\end{figure}
\end{document}
附录:
您可能喜欢使用以下替代解决方案copyrightbox
:
\documentclass{article}
\usepackage{graphicx}
\usepackage{caption} % for source
\newcommand{\imagesource}[1]{\hfill\scriptsize Source: #1}
\usepackage{copyrightbox}
\makeatletter
\renewcommand{\CRB@setcopyrightparagraphstyle}{\raggedleft} % new
\makeatother
\begin{document}
\begin{figure}[ht]
\centering
\setkeys{Gin}{width=\linewidth}
\begin{tabular}{p{0.45\linewidth}p{0.34\linewidth}}
\copyrightbox[b]{\includegraphics{example-image-duck}}{(EU 2020)}
&
\copyrightbox[b]{\includegraphics{example-image-duck}}{(IEA 2019)}
\\[-3ex]
\caption{This is a caption for the first image.}
\label{fig:image1}
& \caption{This is a caption for the second image.}
\label{fig:image2}
\end{tabular}
\end{figure}
\end{document}
答案2
以下 MWE 允许重现原始问题中显示的输出。
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{graphicx}
\usepackage{caption} % for source
\usepackage{float}
\usepackage[export]{adjustbox} % valign
\newcommand{\imagesource}[1]{{\scriptsize Source: #1}}
\usepackage[export]{adjustbox}
\usepackage{fullpage} % full wide page, small margins
\begin{document}
\begin{figure}[H]
\centering
\begin{minipage}[t]{.475\textwidth} % [t][][b]
\begin{tabular}[t]{ @{} r @{} }
\includegraphics[width = .9\linewidth,valign=t]{example-image} \\
\imagesource{(EU 2020)}
\end{tabular}
\end{minipage}\hfill
\begin{minipage}[t]{.475\textwidth}
\begin{tabular}[t]{ @{} r @{} }
\includegraphics[width = .7\linewidth,valign=t]{example-image} \\
\imagesource{(IEA 2019)}
\end{tabular}
\end{minipage}
\begin{minipage}[t]{.475\textwidth}
\caption{This is a caption for the first image.}\label{fig:image1}
\end{minipage}\hfill
\begin{minipage}[t]{.475\textwidth}
\caption{This is a caption for the second image.}\label{fig:image2}
\end{minipage}
\end{figure}
\end{document}
正如已经猜测的那样在上一个问题的评论中,此行为是由于该包自动将仅跨越一行的字幕水平居中。您可以使用caption
全局(在序言中)或本地(在相应的环境中)关闭此行为。这将导致预期的输出:figure
\captionsetup{singlelinecheck=false}