General ⇒ Problem with tabular, left-align and widths
-
- Posts: 6
- Joined: Thu May 29, 2008 9:45 am
Problem with tabular, left-align and widths
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,
Learn LaTeX easily with newest books:
The LaTeX Beginner's Guide: 2nd edition and perfect for students writing a thesis
The LaTeX Cookbook: 2nd edition full of practical examples for mathematics, physics, chemistry, and more
LaTeX Graphics with TikZ: the first book about TikZ for perfect drawings in your LaTeX thesis
- localghost
- Site Moderator
- Posts: 9202
- Joined: Fri Feb 02, 2007 12:06 pm
Problem with tabular, left-align and widths
Code: Select all
\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}
Best regards
Thorsten
- Attachments
-
- olatex_77411.pdf
- A tabular with left aligned columns and line break.
- (12.75 KiB) Downloaded 1534 times
Board Rules
Avoidable Mistakes
¹ System: TeX Live 2025 (vanilla), TeXworks 0.6.10
Re: Problem with tabular, left-align and widths
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.
-
- Posts: 6
- Joined: Thu May 29, 2008 9:45 am
Re: Problem with tabular, left-align and widths
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.
<recently read> \endtemplate
l.16 ... quick brown fox jumps over the lazy dog &
Any ideas?
Thanks,
- localghost
- Site Moderator
- Posts: 9202
- Joined: Fri Feb 02, 2007 12:06 pm
Problem with tabular, left-align and widths
Board Rules
Avoidable Mistakes
¹ System: TeX Live 2025 (vanilla), TeXworks 0.6.10
- Stefan Kottwitz
- Site Admin
- Posts: 10360
- Joined: Mon Mar 10, 2008 9:44 pm
Problem with tabular, left-align and widths
the code above working if you insert \arraybackslash:
Code: Select all
\begin{tabular}{>{\raggedright}p{0.18\linewidth}>{\raggedright}p{0.38\linewidth}>{\raggedright\arraybackslash}p{0.38\linewidth}}
Problem with tabular, left-align and widths
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:
Code: Select all
>{\raggedright\arraybackslash}X
I have attached the documentation of the package, you can download the package from ctan.
- Attachments
-
- tabularx.pdf
- The documentation to the tabularx package.
- (179.06 KiB) Downloaded 1034 times
-
- Posts: 6
- Joined: Thu May 29, 2008 9:45 am
Problem with tabular, left-align and widths
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,