## LaTeX forum ⇒ General ⇒ Problem with tabular, left-align and widths

LaTeX specific issues not fitting into one of the other forums of this category.
mayngontay
Posts: 6
Joined: Thu May 29, 2008 9:45 am

### Problem with tabular, left-align and widths

Dear all,

I would like to use tabular environment. But I don't like justified-text in columns by using like as follows:
\begin{tabular}{p{0.18\linewidth} p{0.38\linewidth} p{0.38\linewidth}}
...
\end{tabular}

So, the code should be:
\begin{tabular}{l{0.18\linewidth} l{0.38\linewidth} l{0.38\linewidth}}
...
\end{tabular}

(l here is l in letter not 1-one, not slash)

But I got the error:
! LaTeX Error: Illegal character in array arg.
See the LaTeX manual or LaTeX Companion for explanation.
Type H <return> for immediate help.
...
l.4 ...th} l{0.38\linewidth} l{0.38\linewidth}@{}}

Could any one help me to solve this problem?

Thanks,

localghost
Site Moderator
Posts: 9204
Joined: Fri Feb 02, 2007 12:06 pm
I'm not sure if I understood you right. So I worked out an example that shows whether I did.
\documentclass[11pt,a4paper]{article}\usepackage[T1]{fontenc}\usepackage[latin1]{inputenc}\usepackage[english]{babel}\usepackage[font=small,labelfont=bf]{caption}\usepackage[bindingoffset=1cm,centering,includeheadfoot,margin=2cm]{geometry}\usepackage{array}\usepackage{txfonts}            % Postscript font package (Times style) \begin{document}   \begin{centering}     \begin{tabular}{>{\raggedright}p{0.18\linewidth}>{\raggedright}p{0.38\linewidth}>{\raggedright}p{0.38\linewidth}}       The quick brown fox jumps over the lazy dog &       The quick brown fox jumps over the lazy dog &       The quick brown fox jumps over the lazy dog     \end{tabular}   \end{centering}\end{document}

There may be some warning because of filling the lines in the single columns. You can see the resulting document in the attachment.

Best regards
Thorsten
Attachments
olatex_77411.pdf
A tabular with left aligned columns and line break.
LaTeX Community Moderator

¹ System: openSUSE 42.2 (Linux 4.4.52), TeX Live 2016 (vanilla), TeXworks 0.6.1

balf
Posts: 158
Joined: Sat Jan 12, 2008 1:11 am
Try replacing, e.g., p{0.18\linewidth} with >{\raggedright}p{0.18\linewidth} in the preamble of your tabular environment. This requires loading the array package.
You even can define a new column type:
\newcolumntype{P}[1]{>{\raggedright}p{#1\linewidth}} and write \begin{tabular}[P{0.18}P{0.38}P{0.38}}

B.A.

mayngontay
Posts: 6
Joined: Thu May 29, 2008 9:45 am
Your code works with only one row. When I add one more row like below:
\begin{tabular}{>{\raggedright}p{0.18\linewidth}>{\raggedright}p{0.38\linewidth}>{\raggedright}p{0.38\linewidth}}
The quick brown fox jumps over the lazy dog &
The quick brown fox jumps over the lazy dog &
The quick brown fox jumps over the lazy dog\\
The quick brown fox jumps over the lazy dog &
The quick brown fox jumps over the lazy dog &
The quick brown fox jumps over the lazy dog
\end{tabular}

the the error is:

! Extra alignment tab has been changed to \cr.
l.16 ... quick brown fox jumps over the lazy dog &

Any ideas?

Thanks,

localghost
Site Moderator
Posts: 9204
Joined: Fri Feb 02, 2007 12:06 pm
Replace \\ by \tabularnewline. The ragged2e package (part of the ms bundle) offers more capability. You then could replace \raggedright by \Raggedright and keep the \\ for the new tabular line.
LaTeX Community Moderator

¹ System: openSUSE 42.2 (Linux 4.4.52), TeX Live 2016 (vanilla), TeXworks 0.6.1

Stefan Kottwitz
Posts: 9549
Joined: Mon Mar 10, 2008 9:44 pm
Hi mayngontay,
the code above working if you insert \arraybackslash:
\begin{tabular}{>{\raggedright}p{0.18\linewidth}>{\raggedright}p{0.38\linewidth}>{\raggedright\arraybackslash}p{0.38\linewidth}}

Stefan

avp3000
Posts: 49
Joined: Thu Nov 15, 2007 4:22 pm
Hi there,

I am also not sure that I understood you correcly, but i think that what bothers you is the fact that you cannot simulatiously set the width and the justification of a column in a table. I had a similar problem in the past. The most reasonable solution I found to it was the tabularx package. In this package you fix the whole width of a table and than you either specify for a column to be l(left), c(entered), r(ight) or you just write X. The width of the colums, that have the X specification will be determined automatically and will depend on the whole width of the table. However, you can also specify the justification of these columns by using the following command:
>{\raggedright\arraybackslash}X
(choose between \reggedright, \reggedleft or \centering).

I have attached the documentation of the package, you can download the package from ctan.
Attachments
tabularx.pdf
The documentation to the tabularx package.

mayngontay
Posts: 6
Joined: Thu May 29, 2008 9:45 am
Dear all,

The problem has been solved from the fifth post by localghost.
I know that there are other options proposed by balf, Stefan_K, and avp3000 to solve this issue.
Thank you (localghost, balf, Stefan_K, and avp3000) very much.
What you gave me is beyond what I expected.

Regards,