从评论开始这个答案对于类似的问题,我正在尝试对多列文档中两个带有独立标题的无浮动图形的情况进行微调,并致力于以下 MWE:
\documentclass{article}
\usepackage{multicol}
\usepackage{graphicx}
\usepackage[font=small]{caption}
\usepackage{lipsum}
\title{Minimal working example of inline (float free) two beside figures in a two column document}
\author{Pinco Pallino}
\captionsetup{aboveskip=1em} % set space between image and caption
\newcommand{\picsgap}{0.5\columnsep}% this sets horizontal gap between images
\begin{document}
\maketitle
\begin{multicols}{2}
\section*{Introduction}
\lipsum[3][1-4]
\begin{center}
\begin{minipage}{0.85\columnwidth}% this sets the total width of the two figures
\addtolength{\textwidth}{-\picsgap}% allowable width reduced so that \hfill becomes \picsgap long
\begin{minipage}[t]{0.60\textwidth}
\centering
\includegraphics[width=\textwidth]{example-image-a}%
\captionof{figure}{Short caption.}
\end{minipage}\hfill
\begin{minipage}[t]{0.40\textwidth}
\centering
\includegraphics[width=\textwidth]{example-image-b}%
\captionof{figure}{\lipsum[3][4-6]}
\end{minipage}
\end{minipage}
\end{center}
\lipsum[3-4]
\end{multicols}
\end{document}
上面的代码允许选择一些参数(整体宽度、图像之间的水平间隙、标题上方的垂直空间),但我希望能够(可选)做更多的事情,例如:
- 将两个图像垂直居中(现在图像垂直对齐到它们的底部)
- 将两个图片+标题块垂直居中
- 自动调整图像大小,使它们具有相同的高度
- 自动调整图像大小,使它们具有相同的面积
如果我应该分开这些问题,请告诉我。
跟进
问题 1 在第二个脚本中得到解决egreg 的回答(删除表格环境以保持标题距离统一)。
问题 2、3 和 4 已解决我自己的答案。
答案1
您可以测量较高的图像,并在较矮的图像旁边排版一条具有该高度的隐形规则。
\documentclass{article}
\usepackage{multicol}
\usepackage{graphicx}
\usepackage[font=small]{caption}
\usepackage{lipsum}
\title{Minimal working example of inline (float free) two beside figures in a two column document}
\author{Pinco Pallino}
\newsavebox{\imagebox}
\begin{document}
\maketitle
\begin{multicols}{2}
\section*{Introduction}
\lipsum[3][1-4]
\begin{center}
\captionsetup{aboveskip=1ex} % less space between image and caption
% measure the highest image
\sbox{\imagebox}{\includegraphics[width=0.51\columnwidth]{example-image-a}}
\hfill
\begin{minipage}[t]{0.51\columnwidth}
\centering
\includegraphics[width=\textwidth]{example-image-a}%
\captionof{figure}{Short caption.}
\end{minipage}\quad
\begin{minipage}[t]{0.34\columnwidth}
\centering
\rule{0pt}{\ht\imagebox}%
\includegraphics[width=\textwidth]{example-image-b}%
\captionof{figure}{\lipsum[3][4-6]}
\end{minipage}\hspace*{\fill}
\end{center}
\lipsum[3-4]
\end{multicols}
\end{document}
如何使各图像垂直居中?
\documentclass{article}
\usepackage{multicol}
\usepackage{graphicx}
\usepackage[export]{adjustbox}
\usepackage[font=small]{caption}
\usepackage{lipsum}
\title{Minimal working example of inline (float free) two beside figures in a two column document}
\author{Pinco Pallino}
\newsavebox{\imagebox}
\begin{document}
\maketitle
\begin{multicols}{2}
\section*{Introduction}
\lipsum[3][1-4]
\begin{center}
\captionsetup{aboveskip=1ex}
% measure the highest image
\sbox{\imagebox}{\includegraphics[width=0.51\columnwidth]{example-image-a}}
\hfill
\begin{minipage}[t]{0.51\columnwidth}
\centering
\includegraphics[width=\textwidth,valign=c]{example-image-a}
\captionof{figure}{Short caption.}
\end{minipage}\quad
\begin{minipage}[t]{0.34\columnwidth}
\centering
\begin{tabular}{@{}c@{}}
\rule{0pt}{\ht\imagebox}
\end{tabular}%
\includegraphics[width=\textwidth,valign=c]{example-image-b}%
\captionof{figure}{\lipsum[3][4-6]}
\end{minipage}\hspace*{\fill}
\end{center}
\lipsum[3-4]
\end{multicols}
\end{document}
答案2
问题 2 很容易解决,只需对内部小页面使用c
选项(而不是)。t
问题 3 可以通过一些数学运算来解决(放在小页面之前):
\setbox0\hbox{\includegraphics{\imga}}%
\setbox1\hbox{\includegraphics{\imgb}}%
\edef\widratiox{\fpeval{1/(1+(\ht0*\wd1/(\ht1*\wd0)))}}%
\edef\widratioy{\fpeval{1-\widratiox}}%
然后分别使用\widratiox\textwidth
和\widratioy\textwidth
作为图像 a 和 b 内部小页面的宽度。
问题 4 的解答方式与问题 3 相同,但使用的数学方法略有不同:
\setbox0\hbox{\includegraphics{\imga}}%
\setbox1\hbox{\includegraphics{\imgb}}%
\edef\widratiox{\fpeval{1/(1+sqrt(\ht0*\wd1/(\ht1*\wd0)))}}%
\edef\widratioy{\fpeval{1-\widratiox}}%