# Custom environment to accept \item

How can I create an environment that takes items in a way similar to lists?

Example:

\begin{myEnv}
\item{AAA}{BBB}
\item{CCC}{DDD}
\end{myEnv}


I'd like the above do something like

\begin{tabular}{|l|l|l|l|}
\hline
AAA & BBB & & \\ \hline
CCC & CCC & & \\ \hline
\end{tabular}

-

## migrated from stackoverflow.comFeb 29 '12 at 16:33

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

Although I'm not entirely clear on your usage, the following is most likely what you're after. The given minimal working example shows your original tabular construction, followed by a myEnv construction. Each \item in within myEnv takes four arguments for the four columns. However, this can also be modified to only take two as in your example:

\documentclass{article}
\usepackage{booktabs}% http://ctan/org/pkg/booktabs
\newenvironment{myEnv}
{\renewcommand{\item}[4]{##1&##2&##3&##4\\}% \item{<one>}{<two>}{<three>}{<four>}
\tabular{*{4}{l}}
\toprule
\midrule
}
{\bottomrule\endtabular}
\begin{document}

\begin{tabular}{|l|l|l|l|}
\hline
AAA & BBB & & \\ \hline
CCC & CCC & & \\ \hline
\end{tabular}

\bigskip

\begin{myEnv}
\item{AAA}{BBB}{CCC}{DDD}
\item{EEE}{FFF}{GGG}{HHH}
\end{myEnv}

\end{document}


I took the liberty of using the booktabs package to produce the second myEnv table, since it produces professional-looking tables (without the use of vertical rules).

The redefinition of \item is local to the environment myEnv, and can therefore still be used in other list environments. Alternatively, you could make your own \item environment (say, \myItem) which would work only inside myEnv.

-