[Tex/LaTex] Multiple columns with minipage, can’t use 100% of \textwidth

minipage

In a document I'm making, I have several cases where I need to organize things into several "columns." For example, here is some code I might use:

\documentclass[letterpaper,12pt]{report}

\usepackage[margin=1in]{geometry}

\begin{document}

\bigskip
\noindent
\begin{minipage}[t]{.45\textwidth}
\raggedright
This is \\
some left-aligned \\
text in a column \\
for demo purposes
\end{minipage}
\hfill
\noindent
\begin{minipage}[t]{.45\textwidth}
\raggedleft
This is \\
some different \\
text, right-aligned \\
for demo purposes, \\
and with more lines.
\end{minipage}

\end{document}

My question is concerning the {.45\textwidth} portion of the definition of the minipage environments. In my first attempt to setup this layout, I used the perhaps more intuitive {.5\textwidth} value on each of them – since I want to use up the entire page, splitting it in half.

However, when I use this value, I get a warning back from TeX:

Overfull \hbox (2.61107pt too wide) in paragraph at lines 8--28

What I'm wondering is, is this behavior just due to the fact that minipage has some implicit padding which I have to deal with via fractions like 0.45, or is there some cleaner way to define this environment?

(Keep in mind, this example is simplified – in the actual document, I may need more than two columns, and the columns may be sized unevenly.)

Best Answer

No, minipage does not provide padding. It's your use of spurious spaces that is causing the problem. To correct for this, use % at the end of a line. Consider, for example:

\noindent
\begin{minipage}[t]{.5\textwidth}
\raggedright
This is \\
some left-aligned \\
text in a column \\
for demo purposes
\end{minipage}% <---------------- Note the use of "%"
\begin{minipage}[t]{.5\textwidth}
\raggedleft
This is \\
some different \\
text, right-aligned \\
for demo purposes, \\
and with more lines.
\end{minipage}

Perhaps something that might be of use that provides some padding similar to that of a twocolumn document is to use a minipage width of \dimexpr.5\textwidth-.5\columnsep.

Here is a visual of the methods discussed to see the difference (I've added frames using \fbox with a zero-width gap/separation):

enter image description here

\documentclass[letterpaper,12pt]{report}

\usepackage[margin=1in]{geometry}
\setlength{\fboxsep}{-\fboxrule}% Just for this example
\begin{document}

\noindent
\fbox{\begin{minipage}[t]{.45\textwidth}
\raggedright
This is \\
some left-aligned \\
text in a column \\
for demo purposes
\end{minipage}}
\hfill
\noindent
\fbox{\begin{minipage}[t]{.45\textwidth}
\raggedleft
This is \\
some different \\
text, right-aligned \\
for demo purposes, \\
and with more lines.
\end{minipage}}

\bigskip

\noindent
\fbox{\begin{minipage}[t]{.5\textwidth}
\raggedright
This is \\
some left-aligned \\
text in a column \\
for demo purposes
\end{minipage}}
\hfill
\noindent
\fbox{\begin{minipage}[t]{.5\textwidth}
\raggedleft
This is \\
some different \\
text, right-aligned \\
for demo purposes, \\
and with more lines.
\end{minipage}}

\bigskip

\noindent
\fbox{\begin{minipage}[t]{\dimexpr.5\textwidth-.5\columnsep}
\raggedright
This is \\
some left-aligned \\
text in a column \\
for demo purposes
\end{minipage}}% <---------------- Note the use of "%"
\fbox{\begin{minipage}[t]{\dimexpr.5\textwidth-.5\columnsep}
\raggedleft
This is \\
some different \\
text, right-aligned \\
for demo purposes, \\
and with more lines.
\end{minipage}}

\end{document}