Discussion:
longtable error: fixed width columns and alignment
(too old to reply)
Karsten Wutzke
2006-07-21 16:04:49 UTC
Permalink
Hello all!

This error makes me mad.

I have a simple document with just one longtable:

-------------------------------------------------

\documentclass[a4paper, 11pt, oneside]{article}

\usepackage[ngerman]{babel}
\usepackage[ansinew]{inputenc}

\usepackage{array}
\usepackage{longtable}

\pagestyle{empty}


\begin{document}

\textbf{I N V O I C E}

%\begin{longtable}{||>{\raggedleft}p{20mm}
% |>{\raggedright}p{50mm}
% |>{\raggedleft}p{20mm}
% |>{\raggedleft}p{20mm}||}
\begin{longtable}{||r|l|r|r||}
foo1 & bar1 & car1 & cdr1 \\
foo2 & bar2 & car2 & cdr2 \\
foo3 & bar3 lohl kj lk jh lkjhdghj h lkj hlkj hlkjk lkj. & car3 & cdr3
\\
foo4 & bar4 & car4 & cdr4 \\
foo5 & bar5 & car5 & cdr5
\end{longtable}

\end{document}

-------------------------------------------------

This code works fine, but I want to specify the column width AND its
alignment. For this purpose, I (try to) use the \begin{longtable}...
outcommented above.

I'm not sure, but the array syntax seems allright to me...

The lower \begin works as desired, but the one above gives errors and
produces unwanted results. This probably has to do with wrong longtable
use. I've tried all day and I have no more ideas.

Latex gives me 3 errors on compilation with the upper \begin (all the
MIDDLE lines! foo2, foo3, and foo4):
.
.
.
! Extra alignment tab has been changed to \cr.
<recently read> \endtemplate

l.22 foo2 &
bar2 & car2 & cdr2 \\
? r ****** <---- I entered r always to see the crappy result******
OK, entering \nonstopmode...
! Extra alignment tab has been changed to \cr.
<recently read> \endtemplate

l.23 ... kj lk jh lkjhdghj h lkj hlkj hlkjk lkj. &
car3 & cdr3 \\
You have given more \span or & marks than there were
in the preamble to the \halign or \valign now in progress.
So I'll assume that you meant to type \cr instead.

! Extra alignment tab has been changed to \cr.
<recently read> \endtemplate

l.24 foo4 & bar4 & car4 &
cdr4 \\
You have given more \span or & marks than there were
in the preamble to the \halign or \valign now in progress.
So I'll assume that you meant to type \cr instead.

Can anyone help me correct it with longtable to have fixed width
columns AND alignment per column set? How to achieve this (-> code)?

TIA

Karsten

PS: I'm quite new to Latex...
David Kastrup
2006-07-21 16:12:15 UTC
Permalink
Post by Karsten Wutzke
Hello all!
This error makes me mad.
%\begin{longtable}{||>{\raggedleft}p{20mm}
% |>{\raggedright}p{50mm}
% |>{\raggedleft}p{20mm}
% |>{\raggedleft}p{20mm}||}
FAQ

6.2.6 Wieso kann ich in einer tabular-Umgebung die letzte Spalte nicht
mit \raggedright linksbündig setzen?
--
David Kastrup, Kriemhildstr. 15, 44793 Bochum
UKTUG FAQ: <URL:http://www.tex.ac.uk/cgi-bin/texfaq2html>
Karsten Wutzke
2006-07-21 17:01:22 UTC
Permalink
Post by David Kastrup
Post by Karsten Wutzke
Hello all!
This error makes me mad.
%\begin{longtable}{||>{\raggedleft}p{20mm}
% |>{\raggedright}p{50mm}
% |>{\raggedleft}p{20mm}
% |>{\raggedleft}p{20mm}||}
FAQ
6.2.6 Wieso kann ich in einer tabular-Umgebung die letzte Spalte nicht
mit \raggedright linksbündig setzen?
--
Sorry, but the last column is not raggedright but raggedleft... or does
this apply, too?

Karsten
David Kastrup
2006-07-21 17:07:31 UTC
Permalink
Post by Karsten Wutzke
Post by David Kastrup
Post by Karsten Wutzke
Hello all!
This error makes me mad.
%\begin{longtable}{||>{\raggedleft}p{20mm}
% |>{\raggedright}p{50mm}
% |>{\raggedleft}p{20mm}
% |>{\raggedleft}p{20mm}||}
FAQ
6.2.6 Wieso kann ich in einer tabular-Umgebung die letzte Spalte nicht
mit \raggedright linksbündig setzen?
Sorry, but the last column is not raggedright but raggedleft... or
does this apply, too?
Guess. Anyway, I should have posted the FAQ address as well as this
is not a hide-and-seek game: the German FAQ address is at the bottom
of my postings to de.comp.text.tex, and I confused the groups. So
here is the address of the FAQ from which I quoted:

<URL:http://www.dante.de/faq/de-tex-faq/>
--
David Kastrup, Kriemhildstr. 15, 44793 Bochum
UKTUG FAQ: <URL:http://www.tex.ac.uk/cgi-bin/texfaq2html>
Enrico Gregorio
2006-07-21 16:27:17 UTC
Permalink
Post by Karsten Wutzke
%\begin{longtable}{||>{\raggedleft}p{20mm}
% |>{\raggedright}p{50mm}
% |>{\raggedleft}p{20mm}
% |>{\raggedleft}p{20mm}||}
\begin{longtable}{||r|l|r|r||}
foo1 & bar1 & car1 & cdr1 \\
foo2 & bar2 & car2 & cdr2 \\
foo3 & bar3 lohl kj lk jh lkjhdghj h lkj hlkj hlkjk lkj. & car3 & cdr3
\\
foo4 & bar4 & car4 & cdr4 \\
foo5 & bar5 & car5 & cdr5
\end{longtable}
-------------------------------------------------
This code works fine, but I want to specify the column width AND its
alignment. For this purpose, I (try to) use the \begin{longtable}...
outcommented above.
I'm not sure, but the array syntax seems allright to me...
The lower \begin works as desired, but the one above gives errors and
produces unwanted results. This probably has to do with wrong longtable
use. I've tried all day and I have no more ideas.
Latex gives me 3 errors on compilation with the upper \begin (all the
.
! Extra alignment tab has been changed to \cr.
<recently read> \endtemplate
l.22 foo2 &
bar2 & car2 & cdr2 \\
? r ****** <---- I entered r always to see the crappy result******
Well, the result is not /crappy/ (not quite a polite word, isn't it?)
but exactly what TeX /must/ do, given your input.

The problem is that \raggedleft changes the meaning of \\; and it
has to do it. The documentation of the array package points out this
problem, although not in a very explicit way.

The solution is either to use \tabularnewline to end each line
of the environment or to say
Post by Karsten Wutzke
{\raggedright\arraybackslash}p{20mm}
in the last column specification (and using \newline in the last column
cells to end lines in the cells themselves.

Ciao
Enrico
Karsten Wutzke
2006-07-21 17:24:39 UTC
Permalink
Post by Enrico Gregorio
Post by Karsten Wutzke
%\begin{longtable}{||>{\raggedleft}p{20mm}
% |>{\raggedright}p{50mm}
% |>{\raggedleft}p{20mm}
% |>{\raggedleft}p{20mm}||}
\begin{longtable}{||r|l|r|r||}
foo1 & bar1 & car1 & cdr1 \\
foo2 & bar2 & car2 & cdr2 \\
foo3 & bar3 lohl kj lk jh lkjhdghj h lkj hlkj hlkjk lkj. & car3 & cdr3
\\
foo4 & bar4 & car4 & cdr4 \\
foo5 & bar5 & car5 & cdr5
\end{longtable}
-------------------------------------------------
This code works fine, but I want to specify the column width AND its
alignment. For this purpose, I (try to) use the \begin{longtable}...
outcommented above.
I'm not sure, but the array syntax seems allright to me...
The lower \begin works as desired, but the one above gives errors and
produces unwanted results. This probably has to do with wrong longtable
use. I've tried all day and I have no more ideas.
Latex gives me 3 errors on compilation with the upper \begin (all the
.
! Extra alignment tab has been changed to \cr.
<recently read> \endtemplate
l.22 foo2 &
bar2 & car2 & cdr2 \\
? r ****** <---- I entered r always to see the crappy result******
Well, the result is not /crappy/ (not quite a polite word, isn't it?)
but exactly what TeX /must/ do, given your input.
The problem is that \raggedleft changes the meaning of \\; and it
has to do it. The documentation of the array package points out this
problem, although not in a very explicit way.
The solution is either to use \tabularnewline to end each line
of the environment or to say
Post by Karsten Wutzke
{\raggedright\arraybackslash}p{20mm}
in the last column specification (and using \newline in the last column
cells to end lines in the cells themselves.
Ciao
Enrico
Thanks for the reply! It works now! (you saved my weekend) *thumbsup*

Which of the two alternatives is the better/purer/expected one??

Karsten
David Kastrup
2006-07-22 10:56:41 UTC
Permalink
Post by Karsten Wutzke
Thanks for the reply! It works now! (you saved my weekend) *thumbsup*
Which of the two alternatives is the better/purer/expected one??
It still is not prohibited reading the dctt FAQ entry I posted.
--
David Kastrup, Kriemhildstr. 15, 44793 Bochum
UKTUG FAQ: <URL:http://www.tex.ac.uk/cgi-bin/texfaq2html>
Ulrich M. Schwarz
2006-07-21 17:16:10 UTC
Permalink
Post by Karsten Wutzke
Hello all!
This error makes me mad.
-------------------------------------------------
\documentclass[a4paper, 11pt, oneside]{article}
\usepackage[ngerman]{babel}
\usepackage[ansinew]{inputenc}
\usepackage{array}
\usepackage{longtable}
\pagestyle{empty}
\begin{document}
\textbf{I N V O I C E}
\begin{longtable}{||>{\raggedleft
\arraybackslash
Post by Karsten Wutzke
}p{20mm}
[...]
Post by Karsten Wutzke
I'm not sure, but the array syntax seems allright to me...
It is. It's only that \raggedleft gives \\ a meaning different from
"end this tabular line".

HTH
Ulrich
--
http://talcum.sarovar.org/ (Current release: 0.5.138 20050911)
Loading...