# Multiple columns with minipage, can't use 100% of \textwidth

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.)

• Is there any reason you don't want to use one of the several packages for managing text in columns? multicol is one, but there are several other options as well. I'm not saying that's how you should do it. I'm just really curious about why you didn't want to use one of the more obvious (to me!) approaches. – cfr Jan 31 '14 at 0:14
• I think it's largely due to some combination of my general unfamiliarity with (La)TeX, as well as the fact that, coming from a programming background, nesting simple layouts to form a complex layout is very natural for me (e.g., a tabular inside a minipage to do two columns with complex text alignment). – CmdrMoozy Jan 31 '14 at 16:37

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):

\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}

• This seems to do the trick. It's still going to take some reading of the TeXbook and experimentation to figure out where it makes sense to end a line with % and where it's unneccessary, but knowing what to look for is most of the battle. Thanks! :) – CmdrMoozy Jan 30 '14 at 23:41
• @CmdrMoozy no really you don't need to read the tex book, it is very simple, minipage is positioned the same way as x. If you go xx they come next to each other, if you go x x with a space or newline between, they get a word space in between. If you want to put a newline between the x without a space in the result you have to comment it out. – David Carlisle Jan 31 '14 at 0:15