I would like to create a dynamic table with \N
columns at the beginning of the page, in which \N
is the number of sections in the whole document, so the value of \N
is set after the table. When I set the value of \N
before the table (in my example, moving line 26 \N=\value{section}
after line 10 \section{section 1}
), everything is alright, but when I set the value of \N
after the table (as it is here in my example), this generates an error.
Here is my code, with the value of \N
set after the table. I suppose it's not so difficult, but I couldn't find a solution. Does anyone have an idea?
\documentclass[12pt,a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[french]{babel}
\usepackage{graphicx}
\newtoks\cols
\newcounter{i}
\newcount\N
\begin{document}
\section{section 1}
\cols={}
\setcounter{i}{1}
\loop
\cols=\expandafter{\the\expandafter\cols\the\value{i}}
\ifnum\value{i}<\N
\cols=\expandafter{\the\cols &}
\stepcounter{i}
\repeat
\begin{tabular}{|*{\N}{c|}}
\the\cols
\end{tabular}
\section{section 2}
\section{section 3}
\section{section 4}
\section{section 5}
\N=\value{section}
\end{document}