将图片放在段落旁边

将图片放在段落旁边

我尝试将图片放在短段落旁边,以便它们的顶部始终对齐。如下图所示。

我的初始代码是这样的:

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{wrapfig}
\usepackage{lipsum}
\usepackage{graphicx}

\begin{document}

\begin{wrapfigure}{r}{0.25\textwidth}
\includegraphics[width=0.2\textwidth]{Dark-Grey-Square.jpg}
\end{wrapfigure}
Here's some information about the figure that is shorter than the image.

\begin{wrapfigure}{r}{0.25\textwidth}
\includegraphics[width=0.2\textwidth]{Dark-Grey-Square.jpg}
\end{wrapfigure}
Here's some information about the figure that is longer than the image \lipsum[1]

\begin{wrapfigure}{r}{0.25\textwidth}
\includegraphics[width=0.2\textwidth]{Dark-Grey-Square.jpg}
\end{wrapfigure}
Shorter again

\end{document}

这显然行不通。我尝试找到一种方法来将图像与段落对齐,但我找到的方法只有当每个段落的高度大于图像时才有效。

我尝试过使用表格但它们造成的问题比解决的问题还多。

我尝试过小型页面,但是它们的行为并不像我想象的那样。

我不一定需要文字像图片中那样环绕第二张图像。

关于如何实现这一点有什么想法吗?

答案1

因此,@David Carlisle 提供的答案效果很好,但经过一番思考后,我发现了一种更适合我特定目的的方法。我使用顶部对齐的迷你页面创建了一个环境。

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{lipsum}
\usepackage{graphicx}

%Create a new minipage environment where paragraphs have indents
\newlength{\currentparindent}
\newenvironment{minipageparindent}[2][c]
  {\setlength{\currentparindent}{\parindent}% save the value
   \noindent\begin{minipage}[#1]{#2}% open the minipage
   \setlength{\parindent}{\currentparindent}% restore the value
  }
  {\end{minipage}}

%Create an environment that creates a paragraph with a picture next to it, both being aligned at the top.
\newenvironment{pictureparagraph}[1]    %argument is an 'includegraphics' command
    {\newcommand\picturetoplace{#1}     % using variable directly gives an error
    \begin{minipageparindent}[t]{0.7\textwidth} %
    \vspace{0pt}    %Make sure that the top base is at the absolute top
    }   
    {
    \end{minipageparindent}
    \begin{minipage}[t]{0.3\textwidth}
    \vspace{0pt}    %Make sure that the top base is at the absolute top of the minipage
    \picturetoplace
    \end{minipage}\\}

\begin{document}

\begin{pictureparagraph}{\includegraphics[width=\textwidth]{Dark-Grey-Square.jpg}}
    Lalala this is a short piece of text to show that the thing works.
\end{pictureparagraph}

\begin{pictureparagraph}{\includegraphics[width=\textwidth]{Dark-Grey-Square.jpg}}
    \lipsum[1]
\end{pictureparagraph}

\begin{pictureparagraph}{\includegraphics[width=\textwidth]{Dark-Grey-Square.jpg}}
    Another short piece of text, but not too short, but not too short, but not too short, but not too short, but not too short, but not too short, but not too short, but not too short, but not too short, but not too short.
\end{pictureparagraph}

\lipsum[1]
\end{document}

相关内容