# Custom tabular environments

I'm trying to create the following structure using the best possible "user-interface" in LaTeX:

---------------------------------------------
|  Week 1  |  1.  Topic 1                        |
|          |  2.  Topic 2                        |
---------------------------------------------
| Week 2   |  1.  Topic 3                        |
|          |  2.  Topic 4                        |
---------------------------------------------

I can, of course create this using a nested enumerate inside a tabular but it would be ugly to look at and difficult to maintain with all the & and the \\ characters.

What I need is a way to cleanly define this structure so that the code looks pretty. The only requirements is the numbering, the tabular structure and of course, page-spanning outlines. If there's a package available, I'd be happy to modify it. (I found the courseoutline package on CTAN by it doesn't have weekly topic breakdown.)

-
Sorry my english is not too good. Does "page-spanning outlines" means you need multi page tables? or/and table over the hole page? I would change my answer if needed ;) –  someonr Jan 3 '12 at 13:20
No problem. Mine isn't that great either. I meant the first option you gave. –  recluze Jan 3 '12 at 15:17

I build a custom enviroment with nice looking tables. The result will be:

\documentclass{article}

\usepackage{etoolbox}
\usepackage{booktabs}

\newcounter{a}
\newcounter{b}[a]
\newbool{firstline}

\newenvironment{mytabular}{%
\setcounter{a}{0}%
\setcounter{b}{0}%
\booltrue{firstline}%
\begin{tabular}{ll}
\toprule}
{\\ \bottomrule\end{tabular}}

\newcommand{\mitem}[2][]{%
\ifbool{firstline}{}{\ifblank{#1}{\\\cmidrule{2-2}}{\\\midrule}}%
\global\boolfalse{firstline}%
#1 \ifblank{#1}{}{\stepcounter{a}\thea}%
&\theb. #2%
}
\newcommand{\witem}[1]{\mitem[Week]{#1}}

\begin{document}
\begin{mytabular}
\mitem[Week]{Subject}
\mitem{Another subject}
\mitem{And another}
\witem{Usage of witem}
\end{mytabular}
\end{document}

or if you don't like this tabular style, you could use this one:

\documentclass{article}

\usepackage{etoolbox}

\newcounter{a}
\newcounter{b}[a]
\newbool{firstline}

\newenvironment{mytabular}{%
\setcounter{a}{0}%
\setcounter{b}{0}%
\booltrue{firstline}%
\begin{tabular}{|l|l|}
\hline}
{\\ \hline\end{tabular}}

\newcommand{\mitem}[2][]{%
\ifbool{firstline}{}{\ifblank{#1}{\\\cline{2-2}}{\\\hline}}%
\global\boolfalse{firstline}%
#1 \ifblank{#1}{}{\stepcounter{a}\thea}%
&\theb. #2%
}
\newcommand{\witem}[1]{\mitem[Week]{#1}}

\begin{document}
\begin{mytabular}
\mitem[Week]{Subject}
\mitem{Another subject}
\mitem{And another}
\witem{Usage of witem}
\end{mytabular}
\end{document}
-
It's simpler to define \newcounter{b}[a], so that b is automatically reset when a is stepped. –  egreg Jan 3 '12 at 13:46
thx. will change this. btw. do you know what "page-spanning outlines" is exactly meaning? –  someonr Jan 3 '12 at 14:06
Remember to use \stepcounter{a}, not \addtocounter{a}{1} –  egreg Jan 3 '12 at 14:08
Thanks exactly what I was looking for. From "Page-spanning", I meant that it will continue on the next page but I changed tabular to the longtable environment from the longtable package and the rest works perfectly. –  recluze Jan 3 '12 at 15:16
Don't forget the \endhead (and endfirsthead) or you will get an underfull vbox error ;) –  someonr Jan 3 '12 at 15:51