# Custom environments with multicolumn header

I tried to create an environment that creates a tabular frame around the content of the environment.

For instance:

\begin{tabular}{|l|l|}
\hline
\multicolumn{2}{|c|}{Team sheet} \\
\hline
\end{tabular}


should become

\begin{example}Team sheet\end{example}


and

\newenvironment{example}{
\begin{tabular}{|l|l|}
\hline
\multicolumn{2}{|c|}{
}{
} \\\hline \end{tabular}
}


But "splitting up" the parentheses of \multicol does not work as straight forward as I wanted due to the obvious parentheses pairing problem. So how do I work around that? Is there an environment for that command available that would allow for this "splitting"?

-

The easiest way to accomplish this is to pass the title as an argument:

\newenvironment{example}[1]
{\begin{tabular}{|l|l|}
\hline
\multicolumn{2}{|c|}{#1} \\
}
{\\\hline \end{tabular}}


and calling it as

\begin{example}{Team sheet}
... the data ...
\end{example}


This better reflects the role of the objects, too.

Adding a frame can be done with the mdframed package.

-

You can save the contents in a savebox and use it inside multicolumn:

\documentclass{article}
\usepackage{array}
\newenvironment{example}{%
\setbox0=\hbox\bgroup
}{
\egroup%
\begin{tabular}{|l|l|}
\hline
\multicolumn{2}{|c|}{\box0}\\\hline
\end{tabular}
}

\begin{document}

\begin{example}
Team sheet
\end{example}

\end{document}


However You can also use the command \fbox.

-