1

I'm having two minipages side by side. The left one includes an image and the right one some text. The text is so-called "enclosed" by a rule at the top and the bottom. The text in turn is aligned to the top (below the top rule). Below the text, I want to insert vertical whitespace so that the bottom rule is aligned to the bottom of the image next to it.

Here's a MWE that puts the bottom rule right below the text:

\documentclass{article}
\usepackage{adjustbox}
\usepackage{graphicx}
\begin{document}
\adjustbox{valign=t}{\begin{minipage}{0.4\textwidth}
    \includegraphics[width=\textwidth]{image.jpeg}
\end{minipage}}
\adjustbox{valign=t}{\begin{minipage}{0.6\textwidth}
    \rule{\textwidth}{0.6mm}\\[0.2cm]
    Text
    \vspace*{\fill}
    \rule{\textwidth}{0.6mm}
\end{minipage}}
\end{document}

How can I achieve the desired effect? Thanks for your help

3

If you would consider to use a further package, I can provide a tcolorbox based solution. If the image is taller than the text, the rules are matched to the image. Otherwise, the rules follow the text:

enter image description here

The source code is:

\documentclass{article}
\usepackage{adjustbox}
\usepackage{graphicx}
\usepackage{lipsum}

\usepackage[skins]{tcolorbox}

\newcommand{\ImageAndText}[2]{%
\begin{tcolorbox}[blankest,sidebyside,
    sidebyside align=top seam,
    sidebyside gap=2mm,
    lefthand width=0.4\textwidth,
    before lower=\par\vspace*{2mm},
    after lower=\par\vspace*{2mm},
    underlay={
      \draw[line width=0.6mm] ([yshift=-0.3mm]segmentation.north east)--(interior.north east);
      \draw[line width=0.6mm] ([yshift=0.3mm]segmentation.south east)--(interior.south east);
    },
    ]
  \includegraphics[width=\linewidth]{#1}
  \tcblower
  #2
\end{tcolorbox}%
}


\begin{document}

\lipsum[1]

\ImageAndText{example-image}{Text}

\ImageAndText{example-image}{\lipsum[2]}

\end{document}
1

We can measure the height of the text with environ and decide whether it's higher than the figure or not.

\documentclass{article}
\usepackage{graphicx}
\usepackage{environ}
\usepackage{lipsum}

\NewEnviron{graphicsandtext}[2][]{%
  % #1 (optional)  = the options for \includegraphics
  % #2 (mandatory) = the image file
  \par\noindent
  \sbox{0}{\includegraphics[#1]{#2}}%
  \raisebox{-\height}{\usebox{0}}%
  \sbox{2}{%
    \begin{minipage}[t]{\dimexpr\columnwidth-\wd0-\columnsep}
    \hrule depth 0.6mm
    \vspace{2pt}
    \BODY
    \par\vspace{2pt}
    \hrule height 0.6mm
    \end{minipage}%
  }%
  \hfill
  \ifdim\dp2<\ht0
    \begin{minipage}[t][\ht0][s]{\dimexpr\columnwidth-\wd0-\columnsep}
    \hrule depth 0.6mm
    \vspace{2pt}
    \BODY
    \par
    \vfill
    \vspace{2pt}
    \hrule height 0.6mm
    \end{minipage}
  \else
    \usebox{2}
  \fi
  \par
}

\begin{document}

\lipsum[1]

\begin{graphicsandtext}[width=0.4\textwidth]{example-image}
Some short text
\end{graphicsandtext}

\bigskip

\begin{graphicsandtext}[width=0.4\textwidth]{example-image}
\lipsum[3]
\end{graphicsandtext}

\end{document}

enter image description here

Here's the effect if the second instance has 0.3\textwidth:

enter image description here

0

It depends on your use case, there are packages for this kind of task (see other answer). But if you want to achieve this with LaTeX on-board tools, you can use the optional height argument from minipage:

\documentclass{article}

\usepackage{graphicx}

\begin{document}

\begin{figure}[tbp]
  \centering
  \includegraphics[height=4cm,keepaspectratio]{example-image-a}%
  \quad
  \begin{minipage}[b][4cm][t]{4cm}
    \rule{\linewidth}{0.6mm}\\[0.2cm]
    Text\par
    \vspace{\fill}
    \rule{\linewidth}{0.6mm}
  \end{minipage}
  \caption{Your Caption}
\end{figure}

\end{document}

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.