# How to properly putting enumerate inside a defined environment?

I'm using an environment to work with a form-type of information, I'm trying to use enumerate for automatic numbering. Here's my current output :

And here's my code,

\begin{document}
\begin{tabforms}
\tabform{a.}{Course name}{:}{History of Art}
\tabform{b.}{Credits}{:}{4 (four)}
\tabform{c.}{Lecturer}{:}{Raisa Andriana}
\tabform{d.}{Room}{:}{Main hall Apolo, building A}
\end{tabforms}
\end{document}

As you can see, I'm defining my alphabet numbering manually. It works exactly as I want, however the information add-ups a lot & sometimes I lost track of the alphabets and had to re-order them from the beginning, that's why I'm trying to use enumerate. Here's my environment :

\newenvironment{tabforms}{%
\begin{longtable}{
>{\raggedright\arraybackslash}p{0.1cm}
>{\raggedright\arraybackslash}p{4.5cm}
>{\raggedright\arraybackslash}p{0.1cm}
>{\raggedright\arraybackslash}p{12cm}  %%% \\
}}{ \end{longtable} \vspace{-1mm}
}
\newcommand\tabform[4]{%
#1 & #2 & #3 & #4  \\ }

I'm trying to implement enumerate on my code using this :

\begin{enumerate}[label=\alph*.]
\item
\item
\end{enumerate}

Which worked perfectly outside an environment. I tried to implement it inside my environment with no luck, this is what I have tried (manual numbering is still there because I just wanted to know if it worked or not) :

\begin{document}
\begin{tabforms}
\begin{enumerate}[label=\alph*.]
\item \tabform{a.}{Course name}{:}{History of Art}
\item \tabform{b.}{Credits}{:}{4 (four)}
\item \tabform{c.}{Lecturer}{:}{Raisa Andriana}
\item \tabform{d.}{Room}{:}{Main hall Apolo, building A}
\end{enumerate}
\end{tabforms}
\end{document}

It didn't work, I encounter these errors in each item line :

Extra }, or forgotten \endgroup
Missing \endgroup inserted
Missing } inserted
Overfull ...

Is it possible to implement enumerate in this case ? and how do I properly put it ?

Don't try to use itemize. Instead, what you want to do is create your own counter. We'll assume that you're not going to have nested tabforms environments (if that's not the case, that will be a bit more involved.

You'll need to create a new counter for your \tabform command, let's call it tabform:

\newcounter{tabform}

Next we want to be able to use it in the environment. We'll want it to print as a lowercase letter and the formatting is determined by the \thetabform command which we can redefine as

\renewcommand{\thetabform}{\alph{tabform}}

(There are also commands \arabic, \Alph, \roman and \Roman that you could have used.)

Now we want to print the number as part of \tabform which will look like this:

\newcommand\tabform[3]{%
\refstepcounter{tabform}\thetabform. & #1 & #2 & #3   \\ }

What we did was to replace the first argument in your long table with the command to print the counter after incrementing its value. Using \refstepcounter allows us to use \label and \ref for cross-referencing.

Finally, we want to make sure that if we have more than one tabforms environment in the document that each one starts with “a.” We do this by setting the tabform counter to 0 as part of the \begin environment definition:

\newenvironment{tabforms}{%
\setcounter{tabform}{0}%
\begin{longtable}{
>{\raggedright\arraybackslash}p{0.1cm}
>{\raggedright\arraybackslash}p{4.5cm}
>{\raggedright\arraybackslash}p{0.1cm}
>{\raggedright\arraybackslash}p{12cm}  %%% \\
}}{ \end{longtable} \vspace{-1mm}
}
• And to forestall a predictable comment, yes, there is \fnsymbol for printing the value of a counter as one of a series of footnote symbols, but it's unlikely to be used in this context. Nov 3, 2020 at 4:30
• It works, thank you. Also your explanation is very detailed and easy to understand, I really appreciate it. Nov 3, 2020 at 4:39

Considering the commands you have already defined, I think that using an enumerate environment is not the easiest way to make the numbering automatic. Instead, you could define a new counter, and increment it at each new call of \tabform to number the corresponding row.

Here's an example I built from yours. I added a new tabcount counter which is reset at the beginning of a tabforms environment. I modified \tabform to make the first argument optional. If it is given it will be placed in the table as in your first example, but if it is not given then tabcount will be incremented and used to number the row automatically.

\documentclass{article}
\usepackage{array}
\usepackage{longtable}

\newcounter{tabcount}
\renewcommand{\thetabcount}{\alph{tabcount}.}

\newenvironment{tabforms}{%
\setcounter{tabcount}{0}
\begin{longtable}{
>{\raggedright\arraybackslash}p{0.1cm}
>{\raggedright\arraybackslash}p{4.5cm}
>{\raggedright\arraybackslash}p{0.1cm}
>{\raggedright\arraybackslash}p{12cm}
}}{ \end{longtable} \vspace{-1mm}
}
\newcommand\tabform[4][]{%
\def\temp{#1}%
\ifx\temp\empty
\refstepcounter{tabcount}%
\thetabcount%
\else
\temp%
\fi%
& #2 & #3 & #4 \\ %
}
\begin{document}
\begin{tabforms}
\tabform{Course name}{:}{History of Art}
\tabform{Credits}{:}{4 (four)}
\tabform{Lecturer}{:}{Raisa Andriana}
\tabform{Room}{:}{Main hall Apolo, building A}
\end{tabforms}
\end{document}

The above example yields the expected output:

• Thank you. Defining a new counter works. Someone else posted an answer with the same approach, literally just 30 seconds faster so I accepted his answer. Nov 3, 2020 at 4:49