I&#39;d like to make a custom environment that will replicate the following code without the \hline and the tabularx<br><br>\begin{tabularx}{|rX|} <br>  \hline<br>   stuff...<br>   last line \\ \hline<br>\end{tabularx}<br>

<br>Suppose the environment is called testbox.  Then the code above could be written as:<br><br>\begin{testbox}<br>  stuff...<br>\end{testbox}<br><br>This is what I&#39;ve come up with for the newenvironment code:<br>\newenvironment{testbox}[1][rX]{\tabularx{\columnwidth}{|#1|} \hline}{ \hline \endtabularx }  <br>

<br>However, the \hline in the end declaration causes a &quot;misplace noalign&quot; error.  If the \hline is removed the end definition, the code compiles with no errors (except no bottom line).<br><br>Here is the smallest code that I can give that causes the error:<br>

<br>\documentclass{article}<br>\usepackage{tabularx}<br><br>\newenvironment{testbox}[1][rX]{%<br>  \tabularx{\columnwidth}{|#1|} \hline}{ \hline \endtabularx }  <br><br>\begin{document}<br>\begin{testbox}<br>  3 &amp; c \\<br>

  4 &amp; c \\<br>\end{testbox}<br>\end{document}<br><br>Can you help me?<br><br>-jekyll<br>