Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I have this environment for consistent tables in my LaTeX documents:

\newenvironment{defaultTable}[2] {
 \@float{table}[h]
 \noindent
 \tabularx{\textwidth}{#1}
 \specialrule{0.5pt}{10pt}{0pt}
 \rowcolor[gray]{.9}
 \gdef\mycaption{#2}
} {
 \bottomrule
 \endtabularx
 \emph{\caption{\mycaption}}
 \end@float
}

Unfortunately, the line with \bottomrule leads to this error, which i don't understand:

! Misplaced \noalign. \bottomrule
->\noalign 
               {\ifnum 0=`}\fi \@aboverulesep =\aboverulesep
\global... l.27 \end{defaultTable}

When I use it inside the environment it works though

\begin{defaultTable}{X X}{Blablah Table}
(..)
\bottomrule
\end{defaultTable}

What am I doing wrong?

share|improve this question
add comment

1 Answer

up vote 2 down vote accepted

This error can be avoided by using the environ package. For example, here's a working modifiation of your code using \NewEnviron of that package:

\documentclass{article}
\usepackage{tabularx} 
\usepackage{booktabs} 
\usepackage[table]{xcolor}
\usepackage{environ}
\makeatletter
\NewEnviron{defaultTable}[2] {
 \@float{table}[h]
 \noindent
 \tabularx{\textwidth}{#1}
 \specialrule{0.5pt}{10pt}{0pt}
 \rowcolor[gray]{.9}
 \gdef\mycaption{#2}
 \BODY
 \bottomrule}[
 \endtabularx
 \emph{\caption{\mycaption}}
 \end@float
]
\makeatother
\begin{document}

\begin{defaultTable}{X X}{Test Table}
1 & 2 \\
\end{defaultTable}

\end{document}

alt text

Note: either end also the last row by \\ (or do it after \BODY). (In the original environment definition \\ before \bottomrule doesn't help.)

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.