# Problem with sizing side-by-side minipages

I've been writing up my resume in LaTeX (for the flashiness and also to get better with LaTeX), and I've been having some trouble with one of the macros I wrote, called \nrccolstring.

\nrccolstring is supposed to take two text fields and make them into side-by-side miniboxes that span all of the space allocated for them. The first minibox is left-justified, and the second minibox is right-justified.

My macro works great when it's on the whole page, but it craps out on me when I nest it inside another minibox (such as the one I'm currently using to control columns).

When I run the attached code, I get the following output:

So what's up?

Why does it fail on the second macro? I get a couple of warnings (shown below), but the document compiles fine.

  Overfull \hbox (2.22221pt too wide) in paragraph at lines 33--34<br>
Underfull \hbox (badness 10000) in paragraph at lines 33--34


What's going on here? There's clearly something I don't understand about how the sizing of a minipage works.

Should I be using something other than miniboxes to achieve the effect?

I thought about using columns or a table originally, but I wanted something that would automatically size the cells to take the entire \textwidth and also make sure that the cells are wide enough (assuming the overall \textwidth is big enough to fit everything).

Thoughts?

\documentclass{article}
\usepackage[top=0.5in, bottom=0.5in, left=0.5in, right=0.5in]{geometry}

\usepackage{calc}
\usepackage{blindtext}

%----------------------- Registers-----------------------------%
\newlength{\registera}
\newlength{\registerb}
%-------------------- Text Field Macros-------------------------%
\newcommand{\CompanyName}{This is a Fictional Company Name}
\newcommand{\Description}{\blindtext}

%-------------------- Formatting Macros------------------------%

\newcommand{\nrccolstring}[2]{
\begingroup
\setlength{\registera}{\widthof{\noindent \raggedright #1}}%
\setlength{\registerb}{\dimexpr \textwidth - \registera \relax}%
\noindent \begin{minipage}[t]{\registera}
\noindent \raggedright #1\\
\end{minipage}
\noindent \begin{minipage}[t]{\registerb}
\noindent \raggedleft #2\\
\end{minipage}
\endgroup}

%------------------------ Body Text ---------------------------%

\begin{document}
\blindtext
\par \bigskip
\par\nrccolstring{\textbf{\CompanyName}}{2011-Present} % Macro works here!
\par
\Description
\par \bigskip

\noindent \begin{minipage}[t]{0.5\textwidth}
\par\nrccolstring{\textbf{\CompanyName}}{2011-Present}  % Macro doesn't work here!
\par
\Description
\end{minipage}
\noindent \begin{minipage}[t]{0.5\textwidth}
\Description
\end{minipage}
\end{document}

-
You have some spurious spaces within your definition of \nrccolstring, as well as the part you say "Macro doesn't work here". Also, you shouldn't end any paragraph with a \. Is the intent just to have a macro that sets something in two parts (one on the left, the other on the right)? –  Werner Feb 27 '13 at 5:30
Yeah, that's the intended purpose of the macro. Is something nicer for doing that kind of thing? (1/3) –  Nicholas Clark Feb 27 '13 at 5:37
This is going to sound dumb (I'm a dumb guy) but can you point me at the line number (or cut/paste) an example of the faulty paragraph? I'm not sure which part you meant by that. (2/3) –  Nicholas Clark Feb 27 '13 at 5:40
Also, I guess I thought LaTeX generally ignored whitespace - how can I fix my macro and keep it readable? (3/3) –  Nicholas Clark Feb 27 '13 at 5:40
@NicholasClark Would be better to use multicol for the two column part, i.e., create an environment rather than macros and minipages. –  Yiannis Lazarides Feb 27 '13 at 5:50

Here is an updated version of your current document:

\documentclass{article}
\usepackage[top=0.5in, bottom=0.5in, left=0.5in, right=0.5in]{geometry}% http://ctan.org/pkg/geometry
\usepackage{calc,blindtext}% http://ctan.org/pkg/{calc,blindtext}

%----------------------- Registers-----------------------------%
\newlength{\registera}
\newlength{\registerb}
%-------------------- Text Field Macros-------------------------%
\newcommand{\CompanyName}{This is a Fictional Company Name}
\newcommand{\Description}{\blindtext}

%-------------------- Formatting Macros------------------------%

\newcommand{\nrccolstring}[2]{%
\begingroup
\setlength{\registera}{\widthof{#1}}%
\setlength{\registerb}{\dimexpr \linewidth - \registera \relax}%
\noindent\begin{minipage}[t]{\registera}
\raggedright #1
\end{minipage}%
\begin{minipage}[t]{\registerb}
\raggedleft #2
\end{minipage}%
\endgroup}

%------------------------ Body Text ---------------------------%

\begin{document}
\blindtext\par
\bigskip
\nrccolstring{\textbf{\CompanyName}}{2011-Present} % Macro works here!
\par
\Description\par
\bigskip

\noindent \begin{minipage}[t]{\dimexpr0.5\textwidth-0.5\columnsep}
\nrccolstring{\textbf{\CompanyName}}{2011-Present}  % Macro doesn't work here!
\par\Description
\end{minipage}\hfill%
\begin{minipage}[t]{\dimexpr0.5\textwidth-0.5\columnsep}
\Description
\end{minipage}
\end{document}


Most notable changes include:

• Using % to remove spurious spaces; LaTeX does ignore spaces in math mode, but not in text mode. It does ignore consecutive spaces, but single spaces are still visible/set. See What is the use of percent signs (%) at the end of lines?
• Using \linewidth instead of \textwidth. This allows for setting your \nrccolstring inside a minipage without it spilling over the box boundary.
• Removing \\ at the end of a paragraph.
-
Wow. You beat me to this by 9 seconds. LOL. Pretty much the same comments too. :) –  A.Ellett Feb 27 '13 at 6:19
Ah, I see what you mean about the spaces and the \\ . Thanks! One other question about this funky macro - if I call \nrccolstring inside of a minipage which is too small for the whole \nrccolstring to fit on one line, the left-side field doesn't seem to linebreak properly (even if I modify the macro so that #2 controls the minipage sze). Any thoughts on why? –  Nicholas Clark Feb 27 '13 at 6:35
Never mind - I found my problem: I had field #1 in \underline and it killed the linebreak. Thanks for the help! Any tricks to make \underline play nicely as input to the macro? –  Nicholas Clark Feb 27 '13 at 6:46
@NicholasClark: \underline doesn't allow for line breaks. You could consider using ulem. However, having boldfaced entries already highlights it sufficiently, in my opinion. –  Werner Feb 27 '13 at 6:53
@Werner I'd vote you up but I don't have the rep yet! Thanks again. –  Nicholas Clark Feb 27 '13 at 7:20