I would like to generate a global table with entries that can be added with a command. I based myself on this post. The issue I have is that I can only display the table after I added all its entries. I wold like to be able to insert the completed table before calling all entries.
What I did so far:
% beginning of global table
\newcommand\startGlobalTable{
\def\GlobalTable{%
\begin{longtable}{ ll }
\hline
Name & Year \\
\hline
}}
% appending element to global table
\newcommand\addGlobalTable[2]{
\edef\GlobalTable{\expandafter\unexpanded\expandafter{%
\GlobalTable%
{#1} & {#2} \
\hline
}}
}
% display the global table
\newcommand\createGlobalTable{\begin{center}\GlobalTable\end{table}\end{center}}
Whit this setup, the global table is displayed at the end of my document:
\startGlobalTable
Some text some text
\addGlobalTable{Hello}{World}
Some different text
\addGlobalTable{Hello}{Moon}
Some final text
\createGlobalTable
However when writing something like this the table at the beginning is (obviously) empty:
\startGlobalTable
\createGlobalTable
Some text some text
\addGlobalTable{Hello}{World}
Some different text
\addGlobalTable{Hello}{Moon}
Some final text
How can I display the table in the beginning of the document containing all entries that will be added later?
Many thanks in advance for your answers!
\edef. That shouldn't be use for arbitrary text. – Ulrike Fischer Feb 05 '23 at 11:01\addGlobalTabledirective? Are the arguments static or dynamic? Put differently, is it crucial where in the document the\addGlobalTable{...}{...}directives occur? – Mico Feb 05 '23 at 11:12\addGlobalTableis called is crucial. – Pa Dalton Feb 05 '23 at 15:11\tableofcontentsor\listoffigures, my actual\addGlobalTableis more complex than in the question – Pa Dalton Feb 05 '23 at 15:14