Vertical alignment of side-by-side minipages
Solution 1
The reason is that the [t]
means align the minipage
with the first (top) baseline. The baseline for the image is under the image, which is perfectly aligned with the first baseline of the text. I see two ways to fix it.
Add a row before and remove the vertical space.
\begin{minipage}[t]{.6\linewidth}
\lipsum[1]
\end{minipage}
\hspace{0.02\linewidth}
\begin{minipage}[t]{.3\linewidth}
\strut\vspace*{-\baselineskip}\newline\includegraphics[width=\linewidth]{example-image}
\end{minipage}
Lower the image with all but one row.
\begin{minipage}[t]{.6\linewidth}
\lipsum[1]
\end{minipage}
\hspace{0.02\linewidth}
\begin{minipage}[t]{.3\linewidth}
\raisebox{-\height+0.7\baselineskip}{\includegraphics[width=\linewidth]{example-image}}
\end{minipage}
Both gives:
Solution 2
You don't really need the minipage around the image
\documentclass{article}
\usepackage{lipsum}
\usepackage[export]{adjustbox}
\usepackage{graphicx}
\begin{document}
\begin{minipage}[t]{.6\linewidth}
\lipsum[1]
\end{minipage}\hfill
\includegraphics[width=.3\linewidth,valign=t]{example-image}
\end{document}
If you do want to put two minipages on a line it is best not to use approximates spacing such as
\begin{minipage}{.6\linewidth}
\lipsum[1]
\end{minipage}
\hspace{0.02\linewidth}
\begin{minipage}{.3\linewidth}
which puts boxes of width .9\textwidth
with a \parindent
to the left and one word space, a space of width 0.02\linewidth
and then another word space between the boxes. This may or may not total one \textwidth
just depending on the stretch and shrink of the two word spaces. It is better to use
\end{minipage}\hfill
\begin{minipage}
as then there is just a single stretchy space between the two boxes.
Related videos on Youtube
Karnivaurus
Updated on August 01, 2022Comments
-
Karnivaurus over 1 year
I want to create some text, which will be positioned on the left-hand side of an image. My Latex code is:
\begin{minipage}{.6\linewidth} \lipsum[1] \end{minipage} \hspace{0.02\linewidth} \begin{minipage}{.3\linewidth} \includegraphics[width=\linewidth]{test.png} \end{minipage}
This gives me the following output:
However, I want the top of the text to be aligned with the top of the picture. Therefore, I tried using the
[t]
argument with the minipage:\begin{minipage}[t]{.6\linewidth} \lipsum[1] \end{minipage} \hspace{0.02\linewidth} \begin{minipage}[t]{.3\linewidth} \includegraphics[width=\linewidth]{test.png} \end{minipage}
However, this gave the following output:
What do I need to do to get my desired vertical alignment?
-
Bernard over 6 yearsDid you try with the
wrapfigure
environment? -
Ben Greenman over 6 yearsTry changing the second minipage to
\begin{minipage}[t][][b]
, see tex.stackexchange.com/questions/132080/…
-
-
Keks Dose about 5 yearsThis finally solved all the nonsense with wrong alignment of my tabulars. I just added at the begin of both (!) minipages
\strut\vspace*{-\baselineskip}\newline
and then they become vertically aligned! Thank you! -
peschü about 4 yearsThank you for the \strut ... it's the only thing that works for me!
-
GcL over 3 yearsThe
\hfill
advice between minipages worked out very well for my use cases. -
GcL over 3 yearsThe
\vstrut\vspace...
worked out very well in getting the minipages to behave as desired by fixing that baseline at their top. It makes the templates that incorporate content generated on the fly simpler to reason about and accommodate.