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

How to left-justify text in a parbox tabular column

3,937 views
Skip to first unread message

ru...@eggneb.astro.ucla.edu

unread,
Aug 25, 1993, 2:48:19 PM8/25/93
to
How can I force the text in a parbox-type column in a table to be ragged-right?

In other words:

I have several columns in a tabular environment defined a "p{3cm}", as opposed
to "c", "l", or whatever.

I want the text in these boxes to be left-justified, or ragged-right.

If I enter the text as {\raggedright da da da da da} it does NOT left justify
the text. It makes it flush left AND right. But is still gives underful \hbox
messages.

If I enter the text as \raggedright{da da da da da} it works just fine, but NOT
for the last column in the table. When I do it this way, it gives the error
"!Misplaced \noalign." at the position of the \hline following the table. I.E.,
this last column is followed by "\\", followed by "\hline", to draw a line at
the bottom of the table. This is how I end all of my tables and it only gives me
a problem when I try this \raggedright option.

Any suggestions?

Much thanks,
Brian
ru...@eggneb.astro.ucla.edu

Pat Duffy

unread,
Aug 25, 1993, 4:43:07 PM8/25/93
to
In article <25gc5j$6...@news.mic.ucla.edu> ru...@eggneb.astro.ucla.edu () writes:
>How can I force the text in a parbox-type column in a table to be ragged-right?

Here's what I do: For each entry that you wish to place left or right, do a

\multicolumn{1}{l}{<text to be moved left>}

This is really ugly, and only shortened up somewhat if you do

\newcommand{\ml}{\multicolumn{1}{l}}

and then use

\ml{<text>}

in your table entries. If there's any other way to do this than by doing this
for every entry in the table, I'd sure like to know about it.
--
Patrick Duffy, du...@theory.chem.ubc.ca

"It's difficult to work in a group when you're omnipotent."
-- "Q", Star Trek the Next Generation

Barry G. Adams

unread,
Aug 25, 1993, 7:32:14 PM8/25/93
to

>How can I force the text in a parbox-type column in a table to be ragged-right?

[stuff deleted]

>Any suggestions?

>Much thanks,
>Brian
>ru...@eggneb.astro.ucla.edu

Try using the flushleft environment. For example

\begin{tabular}{p{2in}p{2in}}
\begin{flushleft}
aaaaaaa \\ aaaaaa \\ aaaaa \\ aaaa \\ aaa \\ aa \\ a
\end{flushleft}
&
\begin{flushleft}
bbbbbbb \\ bbbbbb \\ bbbbb \\ bbbb \\ bbb \\ bb \\ b
\end{flushleft}
\end{tabular}

Barry Adams (ba...@ramsey.cs.laurentian.ca)

David Carlisle

unread,
Aug 26, 1993, 10:45:05 AM8/26/93
to

>>> How to left-justify text in a parbox tabular column

Previous postings have suggested using the flushleft environment
and using

\multicolumn{1}{l}{<text to be moved left>}

The multicolumn solution does not really do the right thing, as it
produces text in LR (aka internal horizontal) mode, so TeX does not
break the lines to the width specified in the p{...} preamble

The flushleft environment unfortunately falls foul of a `feature' of
the way LaTeX terminates `p' columns, it results in a blank line being
produced after the entry.

A better solution is to use the \raggedright command. If the column in
question is the final column of the table, you will need to reinstate
the \\ comand to terminate a table row, as \ragedright redefines it.

One way to do this is to go

\newcommand{\PreserveBackslash}[1]{\let\temp=\\#1\let\\=\temp}

and use \PreserveBackslash\raggedright at the start of each entry.
...

To see the difference, compare

\documentstyle{article}


\newcommand{\PreserveBackslash}[1]{\let\temp=\\#1\let\\=\temp}


\begin{document}

\begin{tabular}{cp{1in}}
xxx & \multicolumn{1}{l}{Some ragged right text. Some ragged right text.}\\
yyy & \multicolumn{1}{l}{Some ragged right text. Some ragged right text.}\\
\end{tabular}

\begin{tabular}{cp{1in}}
xxx & \begin{flushleft}
Some ragged right text. Some ragged right text.\end{flushleft}\\
yyy & \begin{flushleft}
Some ragged right text. Some ragged right text.\end{flushleft}\\
\end{tabular}
%
%
\begin{tabular}{cp{1in}}
xxx & \PreserveBackslash\raggedright
Some ragged right text. Some ragged right text.\\
yyy & \PreserveBackslash\raggedright
Some ragged right text. Some ragged right text.
\end{tabular}

\end{document}

If you use array.sty from the ARRAY package at any CTAN server, you
can go

\newcolumntype{P}[1]{>{\PreserveBackslash\raggedright}p{#1}}

and then the above could be shortened to

%
\begin{tabular}{cP{1in}}
xxx &Some ragged right text. Some ragged right text.\\
yyy &Some ragged right text. Some ragged right text.
\end{tabular}


David

0 new messages