I have this code where the part marked A
is the same as the part marked B
except that .4
in A
is .45
in B
. Even though they are so similar the first one puts the images side by side with the rightmost one flush right but the second one does not do that. I don't understand why there is a difference. Could someone explain that.
\documentclass{article}
\usepackage{colortbl}
\usepackage{graphicx}
\begin{document}
\begin{center}
\noindent\colorbox{blue}{\parbox[t][0.5cm][c]{\textwidth}{\bfseries{HEADER}}}
\end{center}
\noindent\begin{minipage}{\textwidth}
%A
\noindent\begin{minipage}[b]{.4\textwidth}
\includegraphics[width=2in]{elephant}
Some text.
\end{minipage}
\hfill
\begin{minipage}[b]{.4\textwidth}
\includegraphics[width=2in]{elephant}
Some more text.
\end{minipage}
\end{minipage}
\vspace{5ex}
%B
\noindent\begin{minipage}{\textwidth}
\noindent\begin{minipage}[b]{.45\textwidth}
\includegraphics[width=2in]{elephant}
Some text.
\end{minipage}
\hfill
\begin{minipage}[b]{.45\textwidth}
\includegraphics[width=2in]{elephant}
Some more text.
\end{minipage}
\end{minipage}
\end{document}
Output:
Creative commons info on elephant image is here
Best Answer
In A) you declare a width of
.4\textwidth
for theminibox
es and a width of2in
for the images, but2in > .4
\textwidth (with default margins); your images in fact are wider that the space reserved for them and the images overflow over the right margin (check this using thedraft
class option and looking at the.log
file).In B) the images have now enough space since
2in <.45\textwidth
, theminipage
s fill the text width but not the images; the image in the second minipage is typeset starting the minipage so you will have a white space of width.45\textwidth-2in
(you can verify this using\fbox
around eachminipage
setting\fboxsep
to0pt
).In your header you are not taking into account
\fboxsep
(the spacing between the box and its contents) and this will cause a overfull box (the width for the\parbox
must be\textwidth-2\fboxsep
).In the following code I used the
draft
class option (overfull\hbox
es will be signaled using a black rule) and enclosed the minipages using a red frame so you can see what is really going on:And the result:
Here's a modified version of your code; using
width=\linewidth
guarantees that the images will take exactly the available space inside theminipage
s: