<?xml version="1.0" encoding="UTF-8"?><rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/">
  <channel>
    <title>latex &amp;mdash; Pavel&#39;s Boring Notes</title>
    <link>https://blog.zorg1331.one/tag:latex</link>
    <description>technical and not so posts which I&#39;ve decided to write</description>
    <pubDate>Sun, 19 Apr 2026 09:27:19 +0000</pubDate>
    <item>
      <title>LaTeX Tips: Table of Contents as... a Table</title>
      <link>https://blog.zorg1331.one/latex-tips-table-of-contents-as</link>
      <description>&lt;![CDATA[Here I provide a minimal example of how to create a custom table of contents (ToC) in LaTeX which appears as a table.&#xA;latex&#xA;!--more--&#xA;&#xA;While experimenting with different ways of presenting some parts of LaTeX document I created a table of contents which looks as a table. See the illustration below:&#xA;&#xA;tabletoc&#xA;&#xA;This was possible with a package called etoc.&#xA;&#xA;A preamble, nothing special here:&#xA;\documentclass{article}&#xA;&#xA;\usepackage{hyperref}&#xA;&#xA;\usepackage{booktabs}&#xA;\usepackage{colortbl}&#xA;\usepackage{nicematrix}&#xA;&#xA;\usepackage{etoc}&#xA;&#xA;etoc allows to fully control how to typeset a ToC and even allows to specify which elements to display in the ToC. Let&#39;s say we introduce a custom sectioning level which we want to display as ToC. Somewhere in preamble we write:&#xA;% dummy sectioning level&#xA;\etocsetlevel{specialsection}{90}&#xA;&#xA;Then we define a command which draws the ToC for us. We have to put it inside &#34;group&#34;:&#xA;\newcommand\mylistofsomething{%&#xA;  \begingroup&#xA;&#xA; % body follows below&#xA;&#xA;  \endgroup&#xA;}&#xA;&#xA;The following calls instruct etoc to handle only the section level we want:&#xA;  \etocglobaldefs% mandatory&#xA;  \etocsetnexttocdepth{4}&#xA;&#xA;  % mimics subsubsection&#xA;  \etocsetlevel{specialsection}{4}&#xA;&#xA;  \etocsetlevel{chapter}{99} % no chapters&#xA;  \etocsetlevel{section}{99} % no sections&#xA;  \etocsetlevel{subsection}{99} % no subsections&#xA;  \etocsetlevel{subsubsection}{99} % no subsections&#xA;  \etocsetlevel{part}{99} % no parts&#xA;&#xA;For our custom section we set a style which in fact creates a table row for each entry:&#xA;  \etocsetstyle{specialsection}&#xA;  {}&#xA;  {\\}&#xA;  {&#xA;    \rowcolor{gray}&#xA;    \etocnumber&amp;\etocname&amp;just text%&#xA;  }&#xA;&#xA;What remains is to set style for the whole ToC and write it. In ToC style definition we tell etoc to create a table:&#xA;  \etocsettocstyle{%&#xA;    \hypersetup{hidelinks}&#xA;    \begin{NiceTabularX}{\textwidth}{X[1,c]X[3,l]X[1,c]}[hvlines]&#xA;      \rowcolor{black}&#xA;      {\textcolor{white}{\textbf{number}}} &amp;&#xA;      {\textcolor{white}{\textbf{name}}} &amp;&#xA;      {\textcolor{white}{\textbf{text}}}&#xA;    }{&#xA;    \end{NiceTabularX}&#xA;  }&#xA;&#xA;  \tableofcontents%&#xA;&#xA;The defined command can be places as usual in the document body:&#xA;\mylistofsomething%&#xA;&#xA;Here is how we can fill our custom ToC:&#xA;\section{section 1}&#xA;&#xA;\subsection{subsection 1}&#xA;&#xA;\subsubsection{subsubsection 1}&#xA;&#xA;\etoctoccontentsline{specialsection}{\protect\numberline{somenumber1} name 1}&#xA;&#xA;\section{section 2}&#xA;&#xA;\subsection{subsection 2}&#xA;&#xA;\subsubsection{subsubsection 2}&#xA;&#xA;\etoctoccontentsline{specialsection}{\protect\numberline{somenumber2} name 2}&#xA;&#xA;\etoctoccontentsline operator ads an entry to the ToC.&#xA;&#xA;Special quirk \protect\numberline{somenumber2}  can be used (this is optionally) to set an entity which can later be referenced as \etocnumer when filling the table.&#xA;&#xA;name 1 or name 2 strings can be referenced as \etocname.&#xA;&#xA;That&#39;s it!]]&gt;</description>
      <content:encoded><![CDATA[<p>Here I provide a minimal example of how to create a custom table of contents (ToC) in LaTeX which appears as a table.
<a href="https://blog.zorg1331.one/tag:latex" class="hashtag"><span>#</span><span class="p-category">latex</span></a>
</p>

<p>While experimenting with different ways of presenting some parts of LaTeX document I created a table of contents which looks as a table. See the illustration below:</p>

<p><img src="https://zorg1331.one/s/rDG5DqskCyQKm7G/preview" alt="tabletoc"></p>

<p>This was possible with a package called <a href="https://www.ctan.org/pkg/etoc">etoc</a>.</p>

<p>A preamble, nothing special here:</p>

<pre><code class="language-tex">\documentclass{article}

\usepackage{hyperref}

\usepackage{booktabs}
\usepackage{colortbl}
\usepackage{nicematrix}

\usepackage{etoc}
</code></pre>

<p><code>etoc</code> allows to fully control how to typeset a ToC and even allows to specify which elements to display in the ToC. Let&#39;s say we introduce a custom sectioning level which we want to display as ToC. Somewhere in preamble we write:</p>

<pre><code class="language-tex">% dummy sectioning level
\etocsetlevel{specialsection}{90}
</code></pre>

<p>Then we define a command which draws the ToC for us. We have to put it inside “group”:</p>

<pre><code class="language-tex">\newcommand\mylistofsomething{%
  \begingroup

 % body follows below

  \endgroup
}
</code></pre>

<p>The following calls instruct <code>etoc</code> to handle only the section level we want:</p>

<pre><code class="language-tex">  \etocglobaldefs% mandatory
  \etocsetnexttocdepth{4}

  % mimics subsubsection
  \etocsetlevel{specialsection}{4}

  \etocsetlevel{chapter}{99} % no chapters
  \etocsetlevel{section}{99} % no sections
  \etocsetlevel{subsection}{99} % no subsections
  \etocsetlevel{subsubsection}{99} % no subsections
  \etocsetlevel{part}{99} % no parts
</code></pre>

<p>For our custom section we set a style which in fact creates a table row for each entry:</p>

<pre><code class="language-tex">  \etocsetstyle{specialsection}
  {}
  {\\}
  {
    \rowcolor{gray}
    \etocnumber&amp;\etocname&amp;just text%
  }
</code></pre>

<p>What remains is to set style for the whole ToC and write it. In ToC style definition we tell <code>etoc</code> to create a table:</p>

<pre><code class="language-tex">  \etocsettocstyle{%
    \hypersetup{hidelinks}
    \begin{NiceTabularX}{\textwidth}{X[1,c]X[3,l]X[1,c]}[hvlines]
      \rowcolor{black}
      {\textcolor{white}{\textbf{number}}} &amp;
      {\textcolor{white}{\textbf{name}}} &amp;
      {\textcolor{white}{\textbf{text}}}
    }{
    \end{NiceTabularX}
  }

  \tableofcontents%
</code></pre>

<p>The defined command can be places as usual in the document body:</p>

<pre><code class="language-tex">\mylistofsomething%
</code></pre>

<p>Here is how we can fill our custom ToC:</p>

<pre><code class="language-tex">\section{section 1}

\subsection{subsection 1}

\subsubsection{subsubsection 1}

\etoctoccontentsline{specialsection}{\protect\numberline{somenumber1} name 1}

\section{section 2}

\subsection{subsection 2}

\subsubsection{subsubsection 2}

\etoctoccontentsline{specialsection}{\protect\numberline{somenumber2} name 2}
</code></pre>

<p><code>\etoctoccontentsline</code> operator ads an entry to the ToC.</p>

<p>Special quirk <code>\protect\numberline{somenumber2}</code> can be used (this is optionally) to set an entity which can later be referenced as <code>\etocnumer</code> when filling the table.</p>

<p><code>name 1</code> or <code>name 2</code> strings can be referenced as <code>\etocname</code>.</p>

<p>That&#39;s it!</p>
]]></content:encoded>
      <guid>https://blog.zorg1331.one/latex-tips-table-of-contents-as</guid>
      <pubDate>Sat, 04 Dec 2021 19:48:22 +0000</pubDate>
    </item>
    <item>
      <title>LaTeX Tips: Indexed List</title>
      <link>https://blog.zorg1331.one/latex-tips-indexed-list</link>
      <description>&lt;![CDATA[Provides an excerpt on how to use indexed lists in LaTeX documents.&#xA;latex&#xA;!--more--&#xA;For me it was surprisingly difficult to find out how to create an indexed list in LaTeX. In terms of programming I am a newbie in LaTeX. Thus, I did not know about LaTeX3. And I did not want to use LuaTeX: it is a bit overkill in my scenario.&#xA;&#xA;So what is the problem? Quite basic:&#xA;&#xA;Initialize a list of something.&#xA;Fill the list with elements (at arbitrary place in document).&#xA;Reference an element of the list by numerical index.&#xA;&#xA;Using LaTeX3 notation we can solve it in the following way.&#xA;&#xA;At first, we define methods in the preamble to create a list, append an element to list and display an element from list:&#xA;\ExplSyntaxOn%&#xA;\NewDocumentCommand{\definesomethinglist}{}&#xA;{&#xA;  \clistclearnew:N \lsomethingclist&#xA;}&#xA;\NewDocumentCommand{\appendtosomethinglist}{m}&#xA;{&#xA;  \clistputright:Nn \lsomethingclist { #1 }&#xA;}&#xA;\NewDocumentCommand{\getsomethinglistitem}{m}{%&#xA;  \textbf{\clistitem:Nn \lsomething_clist { #1 }}&#xA;}&#xA;\ExplSyntaxOff%&#xA;&#xA;Then we initialize a list before begin{document}:&#xA;\definesomethinglist%&#xA;&#xA;Now we can append elements to the list somewhere in the document body:&#xA;\appendtosomethinglist{a note of interest}%&#xA;&#xA;Displaying an element of interest:&#xA;\getsomethinglistitem{1}&#xA;&#xA;Works for me. :-)]]&gt;</description>
      <content:encoded><![CDATA[<p>Provides an excerpt on how to use indexed lists in LaTeX documents.
<a href="https://blog.zorg1331.one/tag:latex" class="hashtag"><span>#</span><span class="p-category">latex</span></a>

For me it was surprisingly difficult to find out how to create an indexed list in LaTeX. In terms of programming I am a newbie in LaTeX. Thus, I did not know about LaTeX3. And I did not want to use LuaTeX: it is a bit overkill in my scenario.</p>

<p>So what is the problem? Quite basic:</p>
<ul><li>Initialize a list of something.</li>
<li>Fill the list with elements (at arbitrary place in document).</li>
<li>Reference an element of the list by numerical index.</li></ul>

<p>Using LaTeX3 notation we can solve it in the following way.</p>

<p>At first, we define methods in the preamble to create a list, append an element to list and display an element from list:</p>

<pre><code class="language-tex">\ExplSyntaxOn%
\NewDocumentCommand{\definesomethinglist}{}
{
  \clist_clear_new:N \l_something_clist
}
\NewDocumentCommand{\appendtosomethinglist}{m}
{
  \clist_put_right:Nn \l_something_clist { #1 }
}
\NewDocumentCommand{\getsomethinglistitem}{m}{%
  \textbf{\clist_item:Nn \l_something_clist { #1 }}
}
\ExplSyntaxOff%
</code></pre>

<p>Then we initialize a list before <code>begin{document}</code>:</p>

<pre><code class="language-tex">\definesomethinglist%
</code></pre>

<p>Now we can append elements to the list somewhere in the document body:</p>

<pre><code class="language-tex">\appendtosomethinglist{a note of interest}%
</code></pre>

<p>Displaying an element of interest:</p>

<pre><code class="language-tex">\getsomethinglistitem{1}
</code></pre>

<p>Works for me. :–)</p>
]]></content:encoded>
      <guid>https://blog.zorg1331.one/latex-tips-indexed-list</guid>
      <pubDate>Wed, 01 Dec 2021 21:42:58 +0000</pubDate>
    </item>
  </channel>
</rss>