Graphics, Figures & Tableserror when using colortbl, longtable and input

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
aidanc
Posts: 7
Joined: Wed Dec 07, 2011 7:04 pm

error when using colortbl, longtable and input

Post by aidanc »

Hi,

I get a misplaced noalign error when I try to input a longtable
which has a \rowcolor command.

The code seems to work when pasted in, instead of input,
but I need to use input as the table is automatically generated.

Any help or workaround would be greatly appreciated.

thanks
Aidan

Code: Select all

\documentclass[10.5pt, a4paper]{article}
\usepackage[table,dvipsnames]{xcolor}
\usepackage{longtable}

\begin{document}
\begin{longtable}{
r %1
r %2
} 
\caption[short]{TITLE \label{LABEL}}\\
		\input{consol.tex}
\end{longtable}
		
\end{document}

the file consol.tex contains:

Code: Select all

\rowcolor[gray]{0.5}
Norway &2010  \\

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p

Stefan Kottwitz
Site Admin
Posts: 10335
Joined: Mon Mar 10, 2008 9:44 pm

Re: error when using colortbl, longtable and input

Post by Stefan Kottwitz »

Hi Aidan,

this example should work. Could you please post the .log file here, as attachment? There's an "Upload attachment" link below the edit text field, when writing, for this.

Stefan
LaTeX.org admin
aidanc
Posts: 7
Joined: Wed Dec 07, 2011 7:04 pm

Re: error when using colortbl, longtable and input

Post by aidanc »

Hi Stefan,

thanks for the quick reply. Should be attached now.

cheers,
Aidan
Attachments
colortblqn.log
(6.41 KiB) Downloaded 245 times
User avatar
Stefan Kottwitz
Site Admin
Posts: 10335
Joined: Mon Mar 10, 2008 9:44 pm

error when using colortbl, longtable and input

Post by Stefan Kottwitz »

Interesting! I guess it's because \input cannot be expanded. It works with \@@input, but we need to use \makeatletter and \makeatother then:

Code: Select all

\documentclass[10.5pt, a4paper]{article}
\usepackage[table,dvipsnames]{xcolor}
\usepackage{longtable}
\begin{document}
\makeatletter
\begin{longtable}{
r %1
r %2
}
\caption{TITLE \label{LABEL}}\\
  \@@input consol.tex
\end{longtable}
\makeatother
\end{document}
Stefan
LaTeX.org admin
aidanc
Posts: 7
Joined: Wed Dec 07, 2011 7:04 pm

Re: error when using colortbl, longtable and input

Post by aidanc »

Thanks Stefan, I'm glad you can understand it because it's a bit beyond me!

From now on I'll enclose each of my longtables in the makeatletter commands and use @@ input. I guess this might be safer than having the commands at the start and end of the doc, as from my reading it seems they can interfere with other commands.

thanks for your help!
Aidan
Post Reply