6

I am trying to create a layout with two "columns," where the right-hand column itself has two columns, which are right and left aligned, respectively. For instance:

This is some text in the first                Label  Foo
column.                               Another Label  Foo Bar Baz

I am familiar with the technique to create left and righ aligned text on the same line via minipage environments, so extending that idea I've setup the right-hand column to contain a tabular to line up its labels and text. Here's what I have:

\documentclass[letterpaper,12pt]{report}
\usepackage[margin=1in]{geometry}
\begin{document}

\noindent
\begin{minipage}[t]{.49\textwidth}
\flushleft
Some long testing text to illustrate the alignment problem.
\end{minipage}
%
\hfill
%
\noindent
\begin{minipage}[t]{.49\textwidth}
\flushright
\begin{tabular}{r l}
\textbf{Some Long Label} & Bar \\
\textbf{Another Long Label} & Foo Bar Baz \\
\end{tabular}
\end{minipage}

\end{document}

This compiles and mostly works, except for one problem: the top of the text in the table appears somewhat higher than the top of the text in the left minipage. I believe this is due to the fact that tabular's naturally have some extra vertical space before and after them, but I do not know how to fix the problem.

My question is either, how can I fix my code to have the lines of text in each minipage line up vertically or, alternatively, is there some cleaner way of creating this layout without using tabular?

2
  • To fix the alignment you can use the adjustbox package: just remove the right minipage and wrap the content into \adjustbox{valign=t}{<content>}. – Old Nick Dec 27 '13 at 21:25
  • @dcmst The adjustbox works beautifully, even if its contents include something more complicated like a tabularx - thanks! You should add that technique as an answer and I'll accept it. – CmdrMoozy Dec 27 '13 at 21:32
9

You forgot to use [t] also in the tabular:

\documentclass[letterpaper,12pt]{report}
\usepackage[margin=1in]{geometry}
\begin{document}

\noindent
\begin{minipage}[t]{.49\textwidth}
\raggedright
Some long testing text to illustrate the alignment problem.
\end{minipage}% <-- Don't forget this one
%
\hfill
%
\begin{minipage}[t]{.49\textwidth}
\raggedleft
\begin{tabular}[t]{@{} r l @{}}% <-- Don't forget @{}!
\textbf{Some Long Label} & Bar \\
\textbf{Another Long Label} & Foo Bar Baz \\
\end{tabular}
\end{minipage}

\end{document}

enter image description here

Never use \flushleft and \flushright as commands: they exist only because there are the environments flushleft and flushright. The commands to use are \raggedright and \raggedleft.

An easier approach is with tabular*:

\documentclass[letterpaper,12pt]{report}
\usepackage[margin=1in,showframe]{geometry}
\begin{document}

\noindent
\begin{tabular*}{\textwidth}{@{}p{.45\textwidth}@{\extracolsep{\fill}}r@{}}
\raggedright
Some long testing text to illustrate the alignment problem.
&
\begin{tabular}[t]{@{}r l@{}}
\textbf{Some Long Label} & Bar \\
\textbf{Another Long Label} & Foo Bar Baz \\
\end{tabular}
\end{tabular*}

\end{document}

I added showframe just to show the margins.

enter image description here

2
  • This works great, and has a lot of other good advice as well. Thanks! – CmdrMoozy Dec 30 '13 at 17:07
  • +1 for "never use flushleft/flushright". – gented Feb 15 '18 at 11:25
2

Here's a solution that sets each minipage as a tabularx instead:

enter image description here

\documentclass{article}
\usepackage{tabularx}% http://ctan.org/pkg/tabularx
\begin{document}

Some text before.

\noindent
\begin{tabularx}{.5\linewidth}[t]{@{}X@{}}
  Some long testing text to illustrate the alignment problem.
\end{tabularx}%
\begin{tabularx}{.5\linewidth}[t]{%
    >{\raggedleft\bfseries}p{.3\linewidth}
    >{\raggedright\arraybackslash}X@{}}
  Some Long Label & Bar \\
  Another Long Label & Foo Bar Baz
\end{tabularx}%

Some text after.

\end{document}

Alignment of each column is specified using that array package interface (loaded by tabularx).

Note that these blocks will not break across the page boundary.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.