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.

Possible Duplicate:
bottomrule not working in a self-made environment

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
    
I assume the case where it works has {defaultTable} defined not to have \bottomrule, but otherwise be the same. –  Charles Stewart Dec 7 '10 at 14:04
1  
It would have been helpful to have posted a complete working example, including the packages you were assuming to have this code work. –  Alan Munn Apr 4 '11 at 20:41
add comment

migrated from stackoverflow.com Apr 4 '11 at 19:57

This question came from our site for professional and enthusiast programmers.

marked as duplicate by Joseph Wright Aug 31 '11 at 18:17

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

1 Answer

The problem is caused by the \noalign in the definition of \bottomrule. You can define a new version of \bottomrule for use within the environment and then things should work. (You shouldn't redefine \bottomrule in case you use it outside of the environment.) The definition is taken from the booktabs source.

\documentclass{article}
\usepackage{tabularx,booktabs,colortbl}
\makeatletter
\def\envbottomrule{{\ifnum0=`}\fi
  \@aboverulesep=\aboverulesep
  \global\@belowrulesep=\belowbottomsep
  \global\@thisruleclass=\@ne
  \@ifnextchar[{\@BTrule}{\@BTrule[\heavyrulewidth]}}
\newenvironment{defaultTable}[2] {
    \@float{table}[h]
    \noindent
    \tabularx{\textwidth}{#1}
    \specialrule{0.5pt}{10pt}{0pt}
    \rowcolor[gray]{.9}
    \gdef\mycaption{#2}
} {%
    \envbottomrule
    \endtabularx
    \emph{\caption{\mycaption}}
    \end@float
}

\makeatother
\begin{document}
\begin{defaultTable}{XX}{A caption}%
foo & bar\\
foo & bar
\end{defaultTable}

\end{document}
share|improve this answer
add comment

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