[texhax] tabularx inside a newenvironment with hline

Scott Hyde hydes at byuh.edu
Sun Jul 5 00:37:13 CEST 2009


I'd like to make a custom environment that will replicate the following code
without the \hline and the tabularx

\begin{tabularx}{|rX|}
  \hline
   stuff...
   last line \\ \hline
\end{tabularx}

Suppose the environment is called testbox.  Then the code above could be
written as:

\begin{testbox}
  stuff...
\end{testbox}

This is what I've come up with for the newenvironment code:
\newenvironment{testbox}[1][rX]{\tabularx{\columnwidth}{|#1|} \hline}{
\hline \endtabularx }

However, the \hline in the end declaration causes a "misplace noalign"
error.  If the \hline is removed the end definition, the code compiles with
no errors (except no bottom line).

Here is the smallest code that I can give that causes the error:

\documentclass{article}
\usepackage{tabularx}

\newenvironment{testbox}[1][rX]{%
  \tabularx{\columnwidth}{|#1|} \hline}{ \hline \endtabularx }

\begin{document}
\begin{testbox}
  3 & c \\
  4 & c \\
\end{testbox}
\end{document}

Can you help me?

-jekyll
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://tug.org/pipermail/texhax/attachments/20090704/600ad178/attachment.html>


More information about the texhax mailing list