[texhax] Simple line numbering for tabular environments
E. Krishnan
ekmath at asianetindia.com
Thu Jul 19 02:36:18 CEST 2007
On Wed, 18 Jul 2007, James Smith wrote:
> \begin{tabular*}{\linewidth}
> {l>{$}l<{$}>{$}l<{$}}
> \hline\\
> 1&\mathsf{process\_file}(*f:file)\{\\
> 2&\quad l:string\\
> 3&\quad l=\mathsf{read\_line}(f)\\
> 4&\quad\mathsf{while}(l\neq\epsilon))\{\\
> 5&\quad\quad l=\mathsf{read\_line}(f)\\
> 6&\quad\}\\
> 7&\}\\
> \\
> \hline
> \end{tabular*}
>...........
> I need the maths environment...... constantly renumbering the lines when
> I change the listings becomes tiresome, so can I automate this process.
> .......I'd like to keep the tabular* environment if at all possible.
Please try this:
\usepackage{array}
\newcolumntype{M}{>{$}l<{$}}
\newcounter{rowno}
\setcounter{rowno}{0}
\newcommand{\slno}{\addtocounter{rowno}{1}\therowno}
\newcolumntype{N}{>{\slno}l}
\begin{tabular*}{\linewidth}{NMM}
\hline
\multicolumn{3}{c}{}\\
&\mathsf{process\_file}(*f:file)\{\\
&\quad l:string\\
&\quad l=\mathsf{read\_line}(f)\\
&\quad\mathsf{while}(l\neq\epsilon))\{\\
&\quad\quad l=\mathsf{read\_line}(f)\\
&\quad\}\\
&\}\\
\multicolumn{3}{c}{}\\
\hline
\end{tabular*}
--
Krishnan
More information about the texhax
mailing list