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 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"?

share|improve this question
add comment

2 Answers 2

up vote 6 down vote accepted

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.

share|improve this answer
add comment

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.

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.