I have a rather long file with certain information about topics (say, name of the topics and tags associated to it). I want to get an automatic table at the beginning of my document that summarizes this information (somewhat similar to a toc) in the following way: First column is the topic, second are the provided tags, third is the page where the topic is listed.

I want to achieve this through commands (say, \topic and \tags), that I use when starting the new topic and I want LaTeX to produce the table automatically, using the information gathered in all these commands.

Does anyone know how this can be done?

[No MWE provided since I don't even know how to start. I found it kind of hard to explain what I want to achieve, if it is not clear I can try to make it clearer.]


I will try to clarify what I want. In the following code

Topic & Tags & Page \\
Topic 1 & A,B,C & 2 \\
Topic 2 & D,E & 3 \\
Topic 3 & A,E & 4
Topic 1 \\ Tags A,B,C \newpage
Topic 2 \\ Tags D,E \newpage
Topic 3 \\ Tags A,E

I have three topics, each on a new page, with certain tags. On the first page I have a table that summarizes all topics that occur. I now want to have commands, say \topic,\tag, such that I can use \topic{Topic 1} and \tag{A,B,C} when Topic 1 starts, so that the respective row in the table will created automatically (and I don't have to put in the table manually at all).

EDIT 2: Maybe it is possible to adapt the code of the \newlistof command from the tocloft package to create a table (instead of a list), but I don't understand that well enough to do so.

  • 2
    You wrote, "if it is not clear I can try to make it clearer." Yes please. Pretty please, with sugar on top.
    – Mico
    Feb 19, 2022 at 13:19
  • 1
    Being in th estep of clarifying, I'd suggest to add an example of the (kond of) input you have and the tabulated content you want to derive from it. Can be screenshots, which show or visualize this transformation. // From its very nature it might be a better approach to generate the code outside of Latex and just included it. More on this later, perhaps.
    – MS-SPO
    Feb 19, 2022 at 13:51
  • I edited the question and tried to clarify. The tabulated content I want is exactly the one in the table given in the code in the edit. The "input" is the topics and tags (those are written, as in the code in the question, explicitely on the later pages).
    – Martin
    Feb 19, 2022 at 19:57
  • Will you always have \topic{..} command followed by a \tags{..} command? Or will you possibly have \tags{..} scattered throughout the \topic, and one would have to accumulate these into a single list (so that \tags{A} ... \tags{B} ... \tags{C} is equivalent to \tags{A,B,C}, even though the individual \tags are on separate pages)? And the page is associated with the \topic only, not the location of the \tags, right?
    – Werner
    Feb 25, 2022 at 20:45
  • I can gather all tags in one tag command without problem so that nothing needs to be accumulated. Yes, the page that should occur in the table is the one where the topic starts.
    – Martin
    Feb 25, 2022 at 21:41

1 Answer 1


I am not sure, if I understand, what you want to do. But maybe, the following helps a bit.

\usepackage{lipsum}% only for dummy text


  {\usekomafont{sectionentry}{Topics} {\normalfont(Tags)} \hfill {\usekomafont{sectionentrypagenumber}{Page}}}\par
\defcaptionname{english}{\contentsname}{List of Topics}


  [tocentry={Topic 1 \tags{A,B,C}}]
  {Topic 1}

  [tocentry={Topic 2 \tags{D,E}}]
  {Topic 2}

  [tocentry={Longer Topic 3 \tags{A,E}}]
  {Topic 3}

enter image description here

  • This is almost what I want. What I want is that the tags are aligned (as in a table, so that A,B,C and D,E and A,E are directly under Tags).
    – Martin
    Feb 20, 2022 at 19:01

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .