I would like to be able to align two minipage
at the top, without worrying about what is in the minipage
. I am aware of the optional [t]
parameter, but still have some confusion as to how this all works. I tend to think of a minipage
as a regular page in that whatever is placed on it starts at the top and fills the page going across and then down the page, but this does not appear to be the case.
In the MWE example below, I have color coded the sections for reference purposes.
The first case (black) works just as I would expect. The two
minipages
are aligned exactly as I want with the[t]
specifier. No question here.The next case (red) only works if the inner
minipage
also has the[t]
specifier. Why is that necessary? I would have thought that any content would be placed at the top of this page, and since both the outerminipage
had a[t]
things should have aligned at the top.I would like to place a graphic in the second mini page, and still have the two aligned at the top.
The simple case (blue) of using
\includegraphics
directly does not result in the content being aligned at the top.So, then I attempt to put this in a
\parbox
(green) and this too does not yield the desired results.I also try to place the graphic inside an inner
minipage
(brown) and specify the[t]
alignment, and even though this worked in the red section, it does not here. The only difference between the red and brown being that the red section had text, whereas the brown section has a graphic.I am aware of question regarding Aligning image and text on top, with minipages which suggests to place
\vspace{0pt}
at the top of theminipage
, and that does provide the desired alignment (cyan), but adds vertical space at the top.So, my second question is why is the
\vspace{0pt}
necessary when a graphic is included, but not when it is text. This appears to be a hack and wondering if there is a replacement forminipage
that works better without having to worry about exactly what is in the minipage?Also, why did wrapping the figure in a
parbox
(green) or anotherminipage
(brown) not solve this problem?
Here is the MWE:
\documentclass{article}
\usepackage[demo]{graphicx}
\usepackage{lipsum}
\usepackage{xcolor}
\begin{document}
\section{This Works - Aligned at top as desired}
\begin{minipage}[t]{0.6\linewidth}
\lipsum[1]
\end{minipage}
\hfill
\begin{minipage}[t]{0.3\linewidth}
\lipsum[2]
\end{minipage}
\color{red}
\section{Why does inner mini page required the [t]?}
\label{Minipage-in-minipage}
\begin{minipage}[t]{0.6\linewidth}
\lipsum[3]
\end{minipage}
\hfill
\begin{minipage}[t]{0.3\linewidth}
\begin{minipage}[t]{\linewidth}% Why is [t] required here
\lipsum[4]
\end{minipage}
\end{minipage}
\color{blue}
\section{Why are These not aligned at top?}
\begin{minipage}[t]{0.6\linewidth}
\lipsum[3]
\end{minipage}
\hfill
\begin{minipage}[t]{0.3\linewidth}
\includegraphics[width=\linewidth]{foo}
\end{minipage}
\color{green}
\section{Why are These not aligned at top?}
\begin{minipage}[t]{0.6\linewidth}
\lipsum[3]
\end{minipage}
\hfill
\begin{minipage}[t]{0.3\linewidth}
\parbox{\linewidth}{\includegraphics[width=\linewidth]{foo}}
\end{minipage}
\newpage
\color{brown}
\section{Why does this not work with the [t] as it did in red section?}
This worked fine in Section \ref{Minipage-in-minipage}
\begin{minipage}[t]{0.6\linewidth}
\lipsum[3]
\end{minipage}
\hfill
\begin{minipage}[t]{0.3\linewidth}
\begin{minipage}[t]{\linewidth}% Even with [t] here, this does not work
\parbox{\linewidth}{\includegraphics[width=\linewidth]{foo}}
\end{minipage}
\end{minipage}
\color{cyan}
\section{Adding a \textbackslash{}vspace\{0pt\} works}
\begin{minipage}[t]{0.6\linewidth}
\vspace{0pt}% Hack!! But does do the job
\lipsum[3]
\end{minipage}
\hfill
\begin{minipage}[t]{0.3\linewidth}
\vspace{0pt}% Hack!! But does do the job
\begin{minipage}[t]{\linewidth}% Why is [t] required here
\parbox{\linewidth}{\includegraphics[width=\linewidth]{foo}}
\end{minipage}
\end{minipage}
\end{document}
\vspace{0pt}
as the first thing in eachminipage[t]
solve the problem?" is egreg's answer's last paragraph, which begins with "Example 6 is subtler...".