![Minipáginas alineadas a izquierda y derecha, con diseño de tabla](https://rvso.com/image/281504/Minip%C3%A1ginas%20alineadas%20a%20izquierda%20y%20derecha%2C%20con%20dise%C3%B1o%20de%20tabla.png)
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 minipage
entornos, por lo que, ampliando esa idea, configuré la columna de la derecha para que contenga a tabular
para 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 minipage
lí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}
Nunca use \flushleft
y \flushright
como comandos: existen solo porque existen los entornos flushleft
y flushright
. Los comandos a utilizar son \raggedright
y \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é showframe
solo para mostrar los márgenes.
Respuesta2
Aquí hay una solución que establece cada uno minipage
como tabularx
en su lugar:
\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 esoarray
paqueteinterfaz (cargada portabularx
).
Tenga en cuenta que estos bloques no traspasarán el límite de la página.