我正在尝试找到一种自动调整小页面大小的方法。
我正在创建一份报告,其中将包含几个“段落”,左侧有一个浮动图像,右侧有一些文本。它们两者(图像 + 文本)共同构成一个“语义块”。
首先我这样做:
\begin{wrapfigure}{L}{0.15\textwidth}
\centering
\includegraphics[width=0.1\textwidth]{image}\\
\emph{image caption with no "figure1"}
\end{wrapfigure}
Text related to this image\\
Text related to this image\\
Text not related to this image\\
当然,与图像无关的文本被视为与其他文本行一样,打印在图像的右侧。
所以我尝试将其全部包装起来:
\begin{minipage}[c][10cm]{20cm}
\begin{wrapfigure}{L}{0.15\textwidth}
\centering
\includegraphics[width=0.1\textwidth]{image}\\
\emph{image caption with no "figure1"}
\end{wrapfigure}
Text related to this image\\
Text related to this image\\
\end{minipage}
Text not related to this image\\
但确实不方便,而且高度是固定的。
以下是两者的最小“工作”代码:
\documentclass[a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage{graphicx}
\usepackage{wrapfig}
\begin{document}
\begin{wrapfigure}{L}{0.2\textwidth}
\centering
\includegraphics[width=0.2\textwidth]{image}
\emph{image caption with no "figure1"}
\end{wrapfigure}
Text related to this image\\
Text related to this image\\
Text not related to this image\\
\begin{minipage}[c][10cm]{20cm}
\begin{wrapfigure}{L}{0.2\textwidth}
\centering
\includegraphics[width=0.2\textwidth]{image}\\
\emph{image caption with no "figure1"}
\end{wrapfigure}
Text related to this image\\
Text related to this image\\
\end{minipage}
Text not related to this image\\
\end{document}
如果有更好的方法可以不使用 minipage 那就太好了。最后我计划将其变成一个 \newenvironment,它带有两个参数:图像名称和文本,这样我就可以在文章中轻松使用它。
答案1
我非常喜欢浮动环境,但如果不允许浮动,则不必使用它。
\documentclass[a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage{graphicx}
\usepackage{blindtext}
\newcommand{\nonfloatingfigure}[3]{%
\par\addvspace{\abovedisplayskip}
\noindent\begin{minipage}{\linewidth}
\begin{minipage}{.5\linewidth}
\centering
#1\par#2\end{minipage}\begin{minipage}{.5\linewidth}
\raggedright#3
\end{minipage}
\end{minipage}
\par\addvspace{\belowdisplayskip}
}
\begin{document}
\blindtext
\nonfloatingfigure{\includegraphics[width=0.6\textwidth]{example-image-a}}{
image caption with no "figure1"}{
The image on the left shows a Wombat, well it would, but package MWE does not provide
a picture of a Wombat. It definitely should
}
\blindtext
\nonfloatingfigure{\includegraphics[width=0.4\textwidth]{example-image-b}}{
image caption with no "figure1"}{
Text related to this image
Text related to this image
\blindtext
}
Text not related to this image
\blindtext
\end{document}