# Automatic row numbering in a longtable environment

I have a document with every chapter in its own file. I try to autonumbering the table, but it drops missing \endcsname inserted error when I want to step the counter. The main file:

\documentclass[11pt,twoside]{report}
\usepackage{calc}
\usepackage[paperwidth=297mm,%
paperheight=210mm,%
inner=.12\paperwidth,%
outer=.08\paperwidth,%
top=.05\paperheight,%
bottom=.05\paperheight,%
xetex]{geometry}
\usepackage{longtable}
\usepackage[magyar]{babel}

\title{\textbf{Tanmenetek}\\Matematika}
\author{Benkó Tamás}

\newcounter{serial}[chapter]
\newcommand{\serie}{\stepcounter{serial}\arabic{serial}.}

\begin{document}

\maketitle

\chapter{9. osztály}
\input{nine.tex}
\end{document}


The nine.tex file is:

\begin{longtable}{@{\makebox{\serie}}llll}
\multicolumn{1}{@{}l}{Óra címe}&Óra témája&Kompetencia-területek&Eszközök\\
Bevezetés&Bevezetés&-&-\\
\end{longtable}


When I directly write the \serie command into every row, it works right. When I write the \stepcounter in every row, still works, but starts with 0. When the \stepcounter got in the @{} descriptor, I get the mentioned error. I can't figure out the problem, because it with the ususal tabular command works.

• you are presumably using xetex since you give that option to geometry but then babel warns LaTeX Warning: Please use \usepackage{t1enc} with \usepackage[magyar]{babel}, to get accented chars hyphenated. LaTeX Warning: Please use \usepackage[latin2]{inputenc} or \usepackage[utf8]{inputenc} with \usepackage[magyar]{babel}.  so it seems that the magyar settings in babel are for pdftex not xetex Aug 26 '20 at 20:30
• I think you would get the same error in tabular. Aug 26 '20 at 20:39
• The magyar.ldf is for pdflatex, sure, but it works well with xetex. Aug 26 '20 at 22:05
• You should report those messages as a bug in that case, it could easily check a unicode tex was being used. Aug 26 '20 at 22:08
• Ok, but I fear that magyar.ldf is in dormant status, I don't remember any development in the last four years. Aug 26 '20 at 22:16

If you add \usepackage{array} the tabular preamble is processed in a safer way that does not break with fragile commands.

\documentclass[11pt,twoside]{report}
\usepackage{calc}
\usepackage[paperwidth=297mm,%
paperheight=210mm,%
inner=.12\paperwidth,%
outer=.08\paperwidth,%
top=.05\paperheight,%
bottom=.05\paperheight,%
]{geometry}
\usepackage{longtable}
\usepackage[magyar]{babel}
\usepackage{array}
\title{\textbf{Tanmenetek}\\Matematika}
\author{Benkó Tamás}

\newcounter{serial}[chapter]
\newcommand{\serie}{\stepcounter{serial}\theserial.}

\begin{document}

\maketitle

\chapter{9. osztály}

\begin{longtable}{@{\serie}llll}
\multicolumn{1}{@{}l}{Óra címe}&Óra témája&Kompetencia-területek&Eszközök\\