I would like to create an list with some tuples (sectionname, property) so I can add them automatically to a table.

Say I have:


Then magictablecommand should expand as:

      Test & Blup \\
      Plop & Slup \\ 

I need some command, which on the first pass gather section, property pairs. And on the second pass expands magictablecommand (in the first pass it doesn't expand, I don't care really as long as it doesn't emit errors.).

The biggest trouble I have is in determine how to gather the section, property pairs. The rest I can probably figure out.

I would be quite happy with some kind of pointer.

2 Answers 2


The Solution

Here is a solution which provides the functionality you want. With a little tweaking, you can fine tune it to your ultimate needs.


  % Keep the new sections locals and redefine section
  % Create output table

    % Simply close the table, output stream and group



\section{This Section Will not be in Table}

% We start table creation here


% These sections will not be included in the table

\section{Not in Table}

Use your table.

    \input \jobname.tpl
   \caption{My Tuples.}


How It Works?

  • Actually we have defined two magic commands here. One \magictablecommandopen starts your table. \magictablecommandclose finishes your table. So, texts or sections appearing before \magictablecommandopen or after \magictablecommandclose will not be considered for the tupple table. (With some more work, we can even think of turning on and off the table gather environment a number of times.)
  • \magictablecommandopen starts by redefining the \section command so that section name can be saves somewhere (\sectionname). This is done inside a group to keep the changes local. Then it opens an output stream and writes the tabular start commands.
  • \magictablecommandclose writes the tabular close commands, closes the output stream and the group.
  • \property is rather simple. It simply writes a row in the table. The trick here is to use the section name previously saved when the section started.
  • Eventually, you get a \jobname.tpl file which you can use anywhere you want.
  • @EdgarKlerks Glad to be of assistance.
    – Masroor
    Nov 19, 2013 at 17:03

The accepted answer is excellent, but as this deals with sections, it is also possible to do it using etoc. This is certainly a bit idiosyncratic, the advantage, if there is one, is that no group is created which encompasses the tagged sections and also that no extra auxiliary file is needed.

Another approach with etoc would add the property information in the section names in a way invisible in the standard TOCs but made visible on command. But here, we have defined a new dummy sectioning called property and played with it with the tools provided by the package. There are some subtleties though, explained in the code comments.

magic table


\newcommand\property [1]{\etoctoccontentsline{property}{#1}}



\etocdepthtag.toc {notintable}

\section{This Section will not be in Magic Table}

first section

\etocdepthtag.toc {magictable}


second section


third section

% These sections will not be included in the table

\etocdepthtag.toc {notintable}

\section{Not in Magic Table}

fourth section

Use your table.

\begingroup % this group is only if one needs a standard TOC after the magic
            % table 

                 % we can not start the tabular here, else
                 % some macros defined later by etoc will
                 % get lost at the end
                 % of the first cell, which closes a group
                {\caption{Magic Table of my Tuples.}


\etocsetlevel{property}{2}% must use numeric level here and we can not set it at
                          % the same level 1 as section, else \etocsetstyle
                          % below would also modify the style for sections 

% we can not do something like &\etocname, because the & closes a group
% and \etocname then loses its meaning; this is why the & is in the section
% style. 

% in case there are other sectioning levels we don't want to see them in this
% special TOC
% Material not tagged with magictable has no place here
\etocsettagdepth {notintable}{none}
\etocsettagdepth {magictable}{property} % (or the numeric level 2)




Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.