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

Vertical alignment in tabularx

1,529 views
Skip to first unread message

Richard Smith

unread,
Sep 22, 2012, 6:38:33 PM9/22/12
to
I'm sure this ought to be very simple, but I cannot get it to work. I
would like to vertically bottom-align and horizontally right-align one
column in a tabularx environment, but I cannot get the array package's
b column to work. Here's a complete working example:

\documentclass[a4paper,11pt,oneside]{book}
\usepackage{tabularx}
\usepackage{array}
\usepackage{lipsum}
\newcolumntype{e}{>{\hfill}b{5em}}
\begin{document}
\begin{tabularx}{\textwidth}{Xe}
\lipsum[1] & 21~s \\
\end{tabularx}
\end{document}

Any suggestions?

Thanks

Richard

Alain Ketterlin

unread,
Sep 23, 2012, 2:59:07 AM9/23/12
to
Richard Smith <ric...@ex-parrot.com> writes:

> I'm sure this ought to be very simple, but I cannot get it to work. I
> would like to vertically bottom-align and horizontally right-align one
> column in a tabularx environment, but I cannot get the array package's
> b column to work.

To right-align, use >{\raggedleft}b{5em}

b sets the reference point to the bottom of the cell, so that bottom
line will lign with the reference point of the first (left-hand) cell
(which by default is on its top line). Your example, with changes
applied, becomes:

\documentclass[a4paper,11pt,oneside]{book}
\usepackage{tabularx}
\usepackage{array}
\usepackage{lipsum}
\newcolumntype{e}{>{\raggedleft}b{5em}}
\begin{document}
\begin{tabularx}{\textwidth}{Xe}
\lipsum[1] & 21~s blah blah ... \tabularnewline
\end{tabularx}
\end{document}

will lead to something like

yyyyy
xxxxxxxx yyyyy
xxxxxxxx
xxxxxxxx

If by bottom-align you mean:

xxxxxxxx
xxxxxxxx yyyyy
xxxxxxxx yyyyy

then use b for both columns (via \tabularxcolumn).

-- Alain.

Richard Smith

unread,
Sep 24, 2012, 11:49:47 AM9/24/12
to
On Sep 23, 7:59 am, Alain Ketterlin <al...@dpt-info.u-strasbg.fr>
wrote:
> Richard Smith <rich...@ex-parrot.com> writes:
> > I'm sure this ought to be very simple, but I cannot get it to work.  I
> > would like to vertically bottom-align and horizontally right-align one
> > column in a tabularx environment, but I cannot get the array package's
> > b column to work.
>
> To right-align, use >{\raggedleft}b{5em}

[...]

> If by bottom-align you mean:
>
> xxxxxxxx
> xxxxxxxx yyyyy
> xxxxxxxx yyyyy
>
> then use b for both columns (via \tabularxcolumn).

Thanks. That's done exactly what I wanted. As I don't want to change
\tabularxcolumn globally, and as there are likely to be a few other
bits of special formatting (eg. \arraystretch) that I want applying to
this style table but not elsewhere, I've wrapped it up in a new
environment:

\newenvironment{actable}[0]{%
\renewcommand{\tabularxcolumn}[1]{b{##1}}%
\renewcommand{\arraystretch}{1.5}%
\tabularx{\linewidth}%
{@{}X<{~\hrulefill}@{}>{\raggedleft\hrulefill~}b{3.5em}@{}}%
}{\endtabularx}

However if I do this, I find that I have to use \cr instead of \\ as
my line separators. I'm sure I've encountered this before and there's
a simple command called something like \escapelinebreaks that sorts
this out, but I can't seem to find the right thing to put into a
Google search to give me the answer. Any suggestions?

Thanks,
Richard

Dan Luecking

unread,
Sep 25, 2012, 11:07:19 AM9/25/12
to
On Mon, 24 Sep 2012 08:49:47 -0700 (PDT), Richard Smith
<ric...@ex-parrot.com> wrote:

>On Sep 23, 7:59 am, Alain Ketterlin <al...@dpt-info.u-strasbg.fr>
>wrote:
>> Richard Smith <rich...@ex-parrot.com> writes:
>
>\newenvironment{actable}[0]{%
> \renewcommand{\tabularxcolumn}[1]{b{##1}}%
> \renewcommand{\arraystretch}{1.5}%
> \tabularx{\linewidth}%
> {@{}X<{~\hrulefill}@{}>{\raggedleft\hrulefill~}b{3.5em}@{}}%
>}{\endtabularx}
>
>However, if I do this, I find that I have to use \cr instead of \\ as

Put \arraybackslash right after \raggedleft:

{@{}X<{~\hrulefill}@{}>{\raggedleft\arraybackslash\hrulefill~}b{3.5em}@{}}


Dan
To reply by email, change LookInSig to luecking

Richard Smith

unread,
Sep 27, 2012, 4:14:21 PM9/27/12
to
On Sep 25, 4:09 pm, Dan Luecking <LookIn...@uark.edu> wrote:
> On Mon, 24 Sep 2012 08:49:47 -0700 (PDT), Richard Smith
>
> <rich...@ex-parrot.com> wrote:
> >On Sep 23, 7:59 am, Alain Ketterlin <al...@dpt-info.u-strasbg.fr>
> >wrote:
> >> Richard Smith <rich...@ex-parrot.com> writes:
>
> >\newenvironment{actable}[0]{%
> >  \renewcommand{\tabularxcolumn}[1]{b{##1}}%
> >  \renewcommand{\arraystretch}{1.5}%
> >  \tabularx{\linewidth}%
> >    {@{}X<{~\hrulefill}@{}>{\raggedleft\hrulefill~}b{3.5em}@{}}%
> >}{\endtabularx}
>
> >However, if I do this, I find that I have to use \cr instead of \\ as
>
> Put \arraybackslash right after \raggedleft:

Perfect. Thanks.

Richard
0 new messages