2

Boxedminipages line-up as one would expect, whether filled with text or with a graphic, but minipages filled with a graphic line up disconcertedly. (Of course, a workaround is to use \raisebox{<length>}. It is commented out in the minimum working example.)

I was not able to figure out/find how to provide the graphic to be included in the minimum working examples below. I am using http://freemathtexts.org/graphic.pdf but I have to rely on some good soul to fix the includegraphics below.

Here is the minimum working example with Boxed minipages:

\documentclass{book}

\usepackage{boxedminipage}
    \usepackage{graphicx}   

\begin{document}

\begin{boxedminipage}[t]{70mm}
Some text to fill the minipage. Some text to fill the minipage. Some text to fill the minipage. 
\end{boxedminipage}
\begin{boxedminipage}[t]{40mm}
Some text to fill the minipage. Some text to fill the minipage. Some text to fill the minipage. 
\end{boxedminipage}

\bigskip

\begin{boxedminipage}[t]{70mm}
Some text to fill the minipage. Some text to fill the minipage. Some text to fill the minipage. Some text to fill the minipage. 
\end{boxedminipage}
\begin{boxedminipage}[t]{30mm}
\includegraphics[width=\linewidth]{example-image}
\end{boxedminipage}

\end{document}

Here is the minimum working example with the minipages:

\documentclass{book}

\usepackage{boxedminipage}
    \usepackage{graphicx}   

\begin{document}

\begin{minipage}[t]{70mm}
Some text to fill the minipage. Some text to fill the minipage. Some text to fill the minipage. 
\end{minipage}
\begin{minipage}[t]{40mm}
Some text to fill the minipage. Some text to fill the minipage. Some text to fill the minipage. 
\end{minipage}

\bigskip

\begin{minipage}[t]{70mm}
Some text to fill the minipage. Some text to fill the minipage. Some text to fill the minipage. Some text to fill the minipage. 
\end{minipage}
\begin{minipage}[t]{30mm}
%\raisebox{-13mm}{%
\includegraphics[width=\linewidth]{example-image}
%}%
\end{minipage}

\end{document}
2
  • 1
    The mwe package has a few standard images expressly for this purpose. Mar 11, 2016 at 2:32
  • @Zarko Thanks for the edit and thereby showing me how to use mwe here.
    – schremmer
    Mar 11, 2016 at 17:24

2 Answers 2

1

I'm not sure whether your comment about \raisebox means you don't want answers making use of this approach. Nevertheless, here are two approaches,

The first approach avoids the use of \raisebox. I define a command \aestrut as

\newcommand\aestrut{\rule{0pt}{\ht\strutbox}}

and then I use this as the first element of the two minipages that I want to have aligned on the first line.

Some text
\begin{minipage}[t]{70mm}
  \aestrut
  Some text to fill the minipage. Some text to fill the
  minipage. Some text to fill the minipage. Some text to
  fill the minipage.
\end{minipage}
\begin{minipage}[t]{30mm}
  \aestrut\par
  \vspace{-\dimexpr\baselineskip}%%
  \includegraphics[width=\linewidth]{example-image}
\end{minipage}

The issue with \includegraphics is the baseline is the bottom of the image your including. So, something has to be done to correct "where" LaTeX thinks this baseline is. The above results in:

enter image description here

The \vspace{....} is to tweak where the top of the picture gets aligned. Without the \vspace{....}, the result would have looked like:

enter image description here

How you tweak this is up to you.

The second approach is to use a \raisebox command.

Some text
\begin{minipage}[t]{70mm}
  \aestrut
  Some text to fill the minipage. Some text to fill the
  minipage. Some text to fill the minipage. Some text to
  fill the minipage.
\end{minipage}
\begin{minipage}[t]{30mm}
  \raisebox{-\dimexpr\height-\ht\strutbox}{\includegraphics[width=\linewidth]{example-image}}%
\end{minipage}

Notice that I still use the strut that I defined earlier in both minipages. But I also take advantage of \raisebox's knowledge of the height its contained image and adjust the box's height by this amount and \baselineskip.

enter image description here

1
  • 1. I mostly wanted to understand why the different behaviors. 2. My only issue with raisebox is that I have to adjust <height> each time. 3. I will study your two answers, which I assume to adjust <height> automatically, a bit later and let you know which way I went. 4. I am grateful.
    – schremmer
    Mar 11, 2016 at 17:13
2

When you do \begin{minipage}[t], the box has its reference point at the same level as the first item in the box (item meaning skip, rule, or box).

In the case of the image, the minipage contains a one line paragraph, consisting just of the image itself; the line is made into a box, the image sitting at the baseline thereof.

This is clear from the image below

enter image description here

This doesn't happen with boxedminipage, because the first item is the top rule.

In order to solve it you have a few strategies.

First strategy: use a skip

\begin{minipage}[t]{70mm}
Some text to fill the minipage. Some text to fill the minipage.
Some text to fill the minipage. Some text to fill the minipage.
\end{minipage}
\begin{minipage}[t]{30mm}
\vspace{-\ht\strutbox}
\includegraphics[width=\linewidth]{example-image}
\end{minipage}

enter image description here

Second strategy: use a rule in both minipages

enter image description here

Third strategy: use adjustbox

\documentclass{book}

\usepackage{graphicx}
\usepackage[export]{adjustbox}

\begin{document}

\begin{minipage}[t]{70mm}
Some text to fill the minipage. Some text to fill the minipage.
Some text to fill the minipage. Some text to fill the minipage.
\end{minipage}
\includegraphics[width=30mm,valign=t]{example-image}

\end{document}

This doesn't even require a second minipage. The result is the same as with the first strategy.

enter image description here

There is a small difference: the top of the image is slightly higher in cases 1 and 3 with respect to case 2. I'd prefer 3 over 2.

Each solution requires no computation.

2
  • 1. Now I understand. Thanks. 2. I like the third strategy. 3. However, since I already have a heavy investment in tcolorbox which of course allows one to emulate minipages, boxed or not, I am considering eliminating minipages altogether from the magnum opus. I would appreciate any comment.
    – schremmer
    Mar 13, 2016 at 0:31
  • 1
    @schremmer tcolorbox is a very powerful package; it mostly depends on what you're going to do, whether using it or not.
    – egreg
    Mar 13, 2016 at 9:51

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .