3

I am trying to place some text and a figure next to each other and trying to avoid wrapfigure at the same time :-)

Placing two minipages inside a framedbox works just fine: the text can be aligned by the [t]op

However, if I place a figure in one minipage instead of text I get misalignment.

MWE:

\documentclass[a4paper,10pt]{scrartcl}
\usepackage[utf8]{inputenc}
\usepackage[danish]{babel}
\usepackage[T1]{fontenc}
\usepackage{graphicx}

% Title Page
\title{Title}
\author{Author}

\begin{document}
\maketitle

\section*{Alignment problems}

\noindent\fbox{
\begin{minipage}[t]{0.7\textwidth}
 A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A
\end{minipage}
\begin{minipage}[t]{0.2\textwidth}
 B B B B B B B B B B B B B B B B B
\end{minipage}
}

\vspace{2cm}

\noindent\fbox{
\begin{minipage}[t]{0.7\textwidth}
 A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A
\end{minipage}
\begin{minipage}[t]{0.2\textwidth}
 \includegraphics[width=0.9\textwidth]{gull}
\end{minipage}
}
\end{document}

This results in something like this Output from the TeX code above

  • Don't forget % after \fbox{ and after the last \end{minipage} in the fbox. Unless you really want more space at either side. – egreg Sep 25 '14 at 9:49
2

The result is what's expected. Probably not what you expected, though.

When you do \parbox[t] or \begin{minipage}[t], the box's reference point is the same as the first item's in it. The reference point always sits on the baseline, the imaginary line where usually letters are placed on.

The reference point of the first item in the box containing the gull image is the bottom of the image, in the text box it's the first line made of A's (because a paragraph is split into line wide boxes).

So you have to make TeX think that the gull image's reference point is higher. The adjustbox package comes to rescue: its valign key allows placing the reference point as if a just line of text is above the baseline and the rest is below.

\documentclass[a4paper,10pt]{scrartcl}
\usepackage[utf8]{inputenc}
\usepackage[danish]{babel}
\usepackage[T1]{fontenc}
\usepackage{graphicx}
\usepackage[export]{adjustbox}

% Title Page
\title{Title}
\author{Author}

\begin{document}
\maketitle

\section*{Alignment problems}

\noindent\fbox{
\begin{minipage}[t]{0.7\textwidth}
 A A A A A A A A A A A A A A A A A A A A A A A A
 A A A A A A A A A A A A A A A A A A A A A A A
\end{minipage}
\begin{minipage}[t]{0.2\textwidth}
 B B B B B B B B B B B B B B B B B
\end{minipage}
}

\vspace{2cm}

\noindent\fbox{
\begin{minipage}[t]{0.7\textwidth}
 A A A A A A A A A A A A A A A A A A A A A A A A
 A A A A A A A A A A A A A A A A A A A A A A A
\end{minipage}
\begin{minipage}[t]{0.2\textwidth}
 \includegraphics[width=0.9\textwidth,valign=t]{../duck}
\end{minipage}
}
\end{document}

enter image description here

Not having a gull, I opted for a duck, which is the favorite animal in this site.

Alternatively, add an invisible item to both boxes:

\begin{minipage}[t]{0.7\textwidth}
 \vspace{0pt}
 A A A A A A A A A A A A A A A A A A A A A A A A
 A A A A A A A A A A A A A A A A A A A A A A A
\end{minipage}
\begin{minipage}[t]{0.2\textwidth}
 \vspace{0pt}
 \includegraphics[width=0.9\textwidth]{../duck}
\end{minipage}

The result will be alike: the first item in both minipages is the vertical space.

  • Thank you very much for that very instructive and very useful reply. The second solution is elegant, albeit 'dirty' -- I'll stick with that. Again thx. – Soren Sep 25 '14 at 9:26
0

Before \includegraphics apply \vspace{-\baselineskip}. This will move the the bottom of the image down by \baselineskip.

  • This answer is a little bit short -- could you elaborate on this a little bit – user31729 Sep 25 '14 at 9:36
  • (a) it will the baseline up not down (b) this much more ad hoc than egreg's answer – Andrew Swann Sep 25 '14 at 10:14
  • Welcome to TeX.SX! An answer should (at best) contain a full compilable example. Such short things would fit better in comments below the question. – LaRiFaRi Sep 25 '14 at 10:41

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.