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

\noalign problem with \input and tabular in memoir class

121 views
Skip to first unread message

mjwil...@gmail.com

unread,
Aug 28, 2007, 1:17:25 PM8/28/07
to
Hi,

I'd really like to \input{} my tabular data and use the memoir
package. If I attempt to compile the following minimal document using
the article class:

\documentclass{article}
\begin{document}
\begin{tabular}{c|c}
\hline
1 & 2 \\
\hline
\input{data}
\hline
5 & 6 \\
\hline
\end{tabular}
\end{document}

pdflatex compiles it without error and the output looks like this, as
expected:

http://img128.imageshack.us/img128/642/picture2ww4.png

Note that data.tex is a file containing the single line "3 & 4 \\" and
no newline.

However, if I change the first line to documentclass{memoir} it no
longer compiles, giving the following error message:

! Misplaced \noalign.
\hline ->\noalign
{\ifnum 0=`}\fi \hrule \@height \arrayrulewidth
\futurelet...
l.10 \hline

I can get the document to compile If I remove the second \hline so
that the LaTeX source now looks like:

\documentclass{memoir}

\begin{document}

\begin{tabular}{c|c}
\hline
1 & 2 \\
\hline
\input{data}
5 & 6 \\
\hline
\end{tabular}
\end{document}

However, the last row is incorrectly aligned, and of course I no
longer have the horizontal rule:

http://img239.imageshack.us/img239/5606/picture3mj7.png

Does anyone know what's going on?

-- Mike Williams

Morten Høgholm

unread,
Aug 28, 2007, 2:18:29 PM8/28/07
to

memoir extends the file loading mechanism by providing \AtBeginFile and
\AtEndFile whose arguments are executed as the names indicate. This is no
problem and not in your case either as these are empty but after inputting
a file the storage bins are emptied. The problem is that this emptying is
an assignment and so starts a new tabular cell and \hline is only allowed
after \\ or other \hlines.

You can use the fact that the tabular environment wraps each tabular cell
in additional groups so one can do an explicit test for which type of
group we are in. If tested to be in an align group *and* in vertical mode
it means TeX still hasn't found what it's looking for (yes I'm a U2 fan!)
namely something to start a new cell and then \noalign can be used. Try
adding this to your preamble:

\makeatletter
\renewcommand*\killm@matf[1]{%
\ifnum 6=\currentgrouptype
\ifvmode
\expandafter\expandafter\expandafter\@firstoftwo
\expandafter\expandafter\expandafter\noalign
\fi
\fi
\@firstofone
{\@namelet{#1-m@mfb}\relax
\@namelet{#1-m@mfe}\relax
}%
}

And Peter, if you are reading this: All those hooks are local both when
setting and resetting. Ought they not be global? In this temporary fix the
resetting is done locally but since it was done locally in the tabular
beforehand it doesn't really change anything...
--
Morten

mjwil...@gmail.com

unread,
Aug 28, 2007, 6:13:12 PM8/28/07
to
On Aug 28, 7:18 pm, Morten Høgholm <morten.hoegh...@gmail.com> wrote:
> Try adding this to your preamble:

[snip]

Thanks very much Morten. I'm not sure I quite understand how that
works, but it seems to have done the trick! Thanks again.

-- Mike

Morten Høgholm

unread,
Aug 29, 2007, 5:20:46 AM8/29/07
to

You're welcome.

Quoting from TeX: The Program: ``It's sort of a miracle whenever \halign
or \valign work, [...]'' (\halign being the primitive underneath
tabular.) TeX in alignment contexts is ideal for programmers with a
desire to become contortionists but can't - at least their code will live
the dream.

Cheers,
--
Morten

Message has been deleted

David Kastrup

unread,
Sep 10, 2007, 7:53:23 AM9/10/07
to
Rainer Schoepf <rainerNOS...@proteosys.com> writes:

> You know that you've reached that state when you get the TeX error
> message about "interwoven alignment preambles"...

Rather easy to get if you play around with \x after
\halign{#\global\futurelet\x\relax\cr\cr}
\show\x

--
David Kastrup

0 new messages