Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Vertical and horizontal alignment of minipages with tabular

302 views
Skip to first unread message

aha...@iastate.edu

unread,
Apr 10, 2011, 9:46:53 PM4/10/11
to aha...@iastate.edu
I have two separate but related questions. I want to use the minipage
environment within a tabular environment so as to create columns of
different widths as it were on the same page.

The first question has to do with vertical spacing. I want the both
minipages to be at the top of a given row even if they are of
different heights. By default the minipage with less material gets
centered. No matter how I mess around with p, t, m, and b in both
tabular and the minipages, I cannot get them both at the top unless I
do so explicitly as in the second example below.

The second question has to do with indenting of the first minipage
within the tabular environment. I am sure it has something to do with
defaults for tabular, but I could not get it to be at the margin
without explicit commands as in the second example below. There has
to a more elegant and automatic way to do this. What I want is the
alignment on the second page but using something more standard like
on the first page.

\documentclass[letterpaper]{article}
\usepackage{array}
\usepackage{lipsum}
\usepackage[lmargin=1in,rmargin=1in,tmargin=1in,bmargin=1in]{geometry}

\begin{document}
\lipsum[6-7] \bigskip
\begin{tabular}{>{\raggedright}p{6cm}l>{\raggedright}p{9cm}}
\begin{minipage}{6cm}
\lipsum[23] \par \bigskip
\lipsum[27]
\end{minipage} &
\begin{minipage}{9cm}
\lipsum[23-26]
\end{minipage}
\end{tabular}

\clearpage

\lipsum[6-7] \bigskip
\begin{tabular}{>{\raggedright\hspace{-21pt}}p{6cm}l>{\raggedright}
p{9cm}}
\raisebox{2.9cm}{
\begin{minipage}{6cm}
\lipsum[23] \par \bigskip
\lipsum[27]
\end{minipage} } &
\begin{minipage}{9cm}
\lipsum[23-26]
\end{minipage}
\end{tabular}

\end{document}

Dan

unread,
Apr 10, 2011, 10:47:28 PM4/10/11
to
On Apr 10, 8:46 pm, "ahal...@iastate.edu" <ahal...@iastate.edu> wrote:
> I have two separate but related questions.  I want to use the minipage
> environment within a tabular environment so as to create columns  of
> different widths as it were on the same page.
>
> The first question has to do with vertical spacing.  I want the both
> minipages to be at the top of a given row even if they are of
> different heights.  By default the minipage with less material gets
> centered.  No matter how I mess around with p, t, m, and b in both
> tabular and the minipages, I cannot get them both at the top unless I
> do so explicitly as in the second example below.

What latex does with the alignment argument to minipage is
set the "reference point" of the minipage to top, middle or
bottom. Then a tabular lines up these reference points. To
get the minipages aligned at their top, one must use [t] as
the first optional argument argument of the minipages (the
alignment argument to tabular is irrelevant.

> The second question has to do with indenting of the first minipage
> within the tabular environment.  I am sure it has something to do with
> defaults for tabular, but I could not get it to be at the margin
> without explicit commands as in the second example below.  There has
> to a more elegant and automatic way to do this.  What I want is the
> alignment on the second page but  using something more standard like
> on the first page.

A tabular is treated as a single large character. If it is the first
thing after a blank line, it starts a paragraph and is indented by
\parindent. So use \noindent\begin{tabular}.

Also, a tabular has default space added between columns,
and also before the first column and after tha last. So use
\noindent\nbegin{tabular}{@()...}
the @ is used to replace the intercolumn space with something.
If you give it an empty argument, that space is replaced with nothing.

>
> \documentclass[letterpaper]{article}
> \usepackage{array}
> \usepackage{lipsum}
> \usepackage[lmargin=1in,rmargin=1in,tmargin=1in,bmargin=1in]{geometry}
>
> \begin{document}
> \lipsum[6-7]  \bigskip
> \begin{tabular}{>{\raggedright}p{6cm}l>{\raggedright}p{9cm}}
> \begin{minipage}{6cm}

Use
\noindent \begin{tabular}{@{}>{\raggedright}p{6cm}l>{\raggedright}
p{9cm}}
\begin{minipage}[t]{6cm}


> \lipsum[23] \par  \bigskip
> \lipsum[27]
> \end{minipage}  &
> \begin{minipage}{9cm}

Use
\begin{minipage}[t]{9cm}

> \lipsum[23-26]
> \end{minipage}
> \end{tabular}

I don't see why you are using both p{} columns and minipages.
surely one or the other is sufficient. p columns get top alignment
by default. In the above example, I get the same result with
\noindent\begin{tabular}{@{}ll}


Dan

GL

unread,
Apr 11, 2011, 5:09:25 AM4/11/11
to
Le 11/04/2011 03:46, aha...@iastate.edu a écrit :
> I have two separate but related questions. I want to use the minipage
> environment within a tabular environment so as to create columns of
> different widths as it were on the same page.
>
> The first question has to do with vertical spacing. I want the both
> minipages to be at the top of a given row even if they are of
> different heights. By default the minipage with less material gets
> centered. No matter how I mess around with p, t, m, and b in both
> tabular and the minipages, I cannot get them both at the top unless I
> do so explicitly as in the second example below.

As Dan said, you should not use minipage inside a tabular, for paragraph
column p, m and b are "minipages" already.

Besides your preamble contains 3 columns while you are using only 2 of
them...

> The second question has to do with indenting of the first minipage
> within the tabular environment. I am sure it has something to do with
> defaults for tabular, but I could not get it to be at the margin
> without explicit commands as in the second example below. There has
> to a more elegant and automatic way to do this. What I want is the
> alignment on the second page but using something more standard like
> on the first page.

As Dan said, a tabular is typeset in a \hbox and starts with
\leavevmode. Therefore \indent is automatically added (depending on
your settings).

Besides, indentation is cancelled inside p, m and b columns. If you
wish the paragraphs to be indented inside the cells, you must explicitly
set \parindent (or use ragged2e.sty - a very good package from
M Scharrer)

When using fixed width columns, you should ensure that the total width
does not exceed \linewidth: if the first column is p{6cm} the second
one should be p{\dimexpr\linewidth-6cm-4\tabcolsep} because the
glue \tabcolsep is added twice at every column edge. You may also
consider to set \tabcolsep to a different value...


I added \hline to control visually the alignments:

%-------------------------------------------------------------


\documentclass[letterpaper]{article}
\usepackage{array}
\usepackage{lipsum}
\usepackage[lmargin=1in,rmargin=1in,tmargin=1in,bmargin=1in]{geometry}

\begin{document}

\lipsum[6-7] \bigskip \edef\ParIndent{\parindent\the\parindent}
\noindent
\begin{tabular}{>{\raggedright\ParIndent}p{6cm}
>{\raggedright\ParIndent}p
{\dimexpr\linewidth-6cm-4\tabcolsep}} \hline


\lipsum[23] \par \bigskip
\lipsum[27]

&
\lipsum[23-26]
\tabularnewline \hline
\end{tabular}

\end{document}
% -------------------------------------------------------------


Rolf Niepraschk

unread,
Apr 11, 2011, 5:15:33 AM4/11/11
to
Am 11.04.2011 11:09, schrieb GL:
...

>
> Besides, indentation is cancelled inside p, m and b columns. If you
> wish the paragraphs to be indented inside the cells, you must explicitly
> set \parindent (or use ragged2e.sty - a very good package from
> M Scharrer)

No! It is a very good package from Martin Schröder.

...Rolf

GL

unread,
Apr 11, 2011, 5:40:03 AM4/11/11
to

Yes ;-) I'm so sorry...

ragged2e is a very good package from Martin Schröder, usefull inside
narrow paragraph boxes, like narrow paragraph columns in tabulars...

Thanks for the correction !


Herbert Voss

unread,
Apr 11, 2011, 6:14:31 AM4/11/11
to
Am 11.04.2011 03:46, schrieb aha...@iastate.edu:
> I have two separate but related questions. I want to use the minipage
> environment within a tabular environment so as to create columns of
> different widths as it were on the same page.
>
> The first question has to do with vertical spacing. I want the both
> minipages to be at the top of a given row even if they are of
> different heights. By default the minipage with less material gets
> centered. No matter how I mess around with p, t, m, and b in both
> tabular and the minipages, I cannot get them both at the top unless I
> do so explicitly as in the second example below.

\documentclass[letterpaper]{article}
\usepackage[lmargin=1in,rmargin=1in,tmargin=1in,bmargin=1in]{geometry}
\usepackage{tabularx,ragged2e}
\usepackage{lipsum}
\newcolumntype{R}[1]{>{\RaggedRight}p{#1}}
\renewcommand\tabularxcolumn[1]{R{#1}}

\begin{document}
\lipsum[6-7] \bigskip

\noindent
\begin{tabularx}{\linewidth}{@{} R{6cm} l X @{}}
\lipsum[23] \par
\lipsum[27]
& a column with less text but very wide &
\lipsum[23]
\end{tabularx}

\end{document}

Herbert

aha...@iastate.edu

unread,
Apr 11, 2011, 11:54:49 PM4/11/11
to
I not need the minipage and the boxes as in p, b and so on.
That was left over from another problem.
Your solution with and without the minipage works great except that by eliminating the tabcolsep at the beginning of the first column, I have no tabcolumsep in any other column. What I would really like is no tabcolumnsep on the left of the first column, 1/2 tabcolumnsep on the right of the first column and the regular tabcolsep on other columns.

Any ideas?

aha...@iastate.edu

unread,
Apr 11, 2011, 11:59:56 PM4/11/11
to
I agree about minipage and tabular and not needing both.
I did not mean for the l to be in the preamble. That was a typo in entering the example. So I only wanted two columns.

I do not want indenting of paragraphs within tabular so the default is fine. But your solution still has the text in the first column indented because of the tabcolsep associated with the left hand side of the first column.

aha...@iastate.edu

unread,
Apr 12, 2011, 12:46:17 AM4/12/11
to
So I just reread page 247 in TLC2 and by using !{} I can get what I want.

\documentclass[letterpaper]{article}
\usepackage{array}
\usepackage{lipsum}
\usepackage[lmargin=1in,rmargin=1in,tmargin=1in,bmargin=1in]{geometry}

\begin{document}
\setlength\tabcolsep{10pt}
\lipsum[6-7] \bigskip
\noindent \begin{tabular}{@{}>{\raggedright}p{6cm}!{}>{\raggedright}p{9cm}}


\lipsum[23] \par \bigskip
\lipsum[27]
&

\lipsum[23-25]
\end{tabular}


\end{document}

aha...@iastate.edu

unread,
Apr 12, 2011, 12:54:54 AM4/12/11
to
So combining you solution with Dan's and using !{} the following works well and allows the width of the second column to be computed automatically as in Herbert's solution using tabularx.

\documentclass[letterpaper]{article}
\usepackage{array}
\usepackage{lipsum}
\usepackage[lmargin=1in,rmargin=1in,tmargin=1in,bmargin=1in]{geometry}

\begin{document}


\setlength\tabcolsep{10pt}
\lipsum[6-7] \bigskip
\noindent
\begin{tabular}{@{}>{\raggedright}p{6cm}!{}

>{\raggedright}p{\dimexpr\linewidth-6cm-4\tabcolsep}}

\lipsum[23] \par \bigskip
\lipsum[27]
&

GL

unread,
Apr 12, 2011, 2:22:55 AM4/12/11
to

tabular adds the \tabcolsep glue between each column, array does the
same with \arraycolsep.

{ l @{} l } removes the glue between the two columns.

What you want is then
{@{} l @{\hskip.5\tabcolsep} l }


aha...@iastate.edu

unread,
Apr 12, 2011, 8:50:01 AM4/12/11
to
On Apr 12, 1:22 am, GL <gouail...@gmail.com> wrote:
> Le 12/04/2011 05:54, ahal...@iastate.edu a crit :

Thanks/ That is helpful.

0 new messages