Minipáginas alineadas a izquierda y derecha, con diseño de tabla

Minipáginas alineadas a izquierda y derecha, con diseño de tabla

Estoy intentando crear un diseño con dos "columnas", donde la columna de la derecha tiene dos columnas, que están alineadas a la derecha e izquierda, respectivamente. Por ejemplo:

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

Estoy familiarizado con la técnica para crear texto alineado a la izquierda y a la derecha en la misma línea a través de minipageentornos, por lo que, ampliando esa idea, configuré la columna de la derecha para que contenga a tabularpara alinear sus etiquetas y texto. Esto es lo que tengo:

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

Esto compila yprincipalmentefunciona, excepto por un problema: la parte superior del texto de la tabla aparece algo más alta que la parte superior del texto de la minipágina izquierda. Creo que esto se debe al hecho de que tabular, naturalmente, tienen algo de espacio vertical adicional antes y después de ellos, pero no sé cómo solucionar el problema.

Mi pregunta es, ¿cómo puedo arreglar mi código para que las líneas de texto en cada minipagelínea estén verticalmente o, alternativamente, hay alguna forma más limpia de crear este diseño sin usar tabular?

Respuesta1

Olvidaste usar [t]también en 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}

ingrese la descripción de la imagen aquí

Nunca use \flushlefty \flushrightcomo comandos: existen solo porque existen los entornos flushlefty flushright. Los comandos a utilizar son \raggedrighty \raggedleft.

Un enfoque más sencillo es con 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}

Agregué showframesolo para mostrar los márgenes.

ingrese la descripción de la imagen aquí

Respuesta2

Aquí hay una solución que establece cada uno minipagecomo tabularxen su lugar:

ingrese la descripción de la imagen aquí

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

La alineación de cada columna se especifica usando esoarraypaqueteinterfaz (cargada portabularx).

Tenga en cuenta que estos bloques no traspasarán el límite de la página.

información relacionada