1

I am writing an template for meeting reports, and want to make this a bit easier. Is there a way of filling an itemize list with section names?

Example:

\section{Section1}
text
\section{Section2}
text

This would generate a bullet list like this:

\begin{itemize}
   \item{Section1}
   \item{Section2}
\end{itemize}

Is this possible? This is for generating a list of subjects we talked about during the meeting. Thanks!

1 Answer 1

2

Easy solution

My first and easy suggestion would be to just use \tableofcontents to create the table of contents as this is much simpler.


Refer to each section (tedious)

However, if you really want a bullet list, you could label every section and refer to it in the bullet list.

\section{Section1}
\label{section 1}
text

\section{Section2}
\label{section 2}
text

\begin{itemize}
    \item Section \ref{section 1}
    \item Section \ref{section 2}
\end{itemize}

Refer to each section name (tedious)

The previous approach only refers to the section number, not the name. This is easily solved by using the nameref package which lets you use the \nameref command:

\usepackage{nameref}

\section{Section 1 is really awesome}
\label{section 1}
text

\begin{itemize}
    \item \nameref{section 1}
\end{itemize}

Using a for loop

Labeling each section and adding it to the itemize is quite tedious. You can save yourself some time if you have lots of sections by using a \foreach command from the pgffor package. This command allows you to loop through a list of numbers ranging from x to y, and use that number to do something, such as writing an \item and then referring to a section number. This does require some planning:

  1. You should label each section with a number with consistent steps between numbers. For ease of use, if you have three sections, you could label them \label{section 1}, \label{section 2} and \label{section 3}.

  2. You need to write the amount of sections in your for loop. The syntax is: \foreach \n in {1,...,x}{Do something} where x is the amount of sections. The \n will then go through the loop and assume a value ranging from 1 to x.

  3. The Do something will be replaced by \item \nameref{section \n}

In the end it should look a little bit like this

\usepackage{nameref}
\usepackage{pgffor}

\section{Section 1 is really awesome}
\label{section 1}
Thobber gained a promotion.

\section{Section with a random name}
\label{section 2}
Thobber's friend joined the company.

\section{Final section where we celebrated the end of meeting}
\label{section 3}
Random cat pictures.

\begin{itemize}
    \foreach \n in {1,...,2}{
        \item \nameref{section \n}
        }
\end{itemize}

Improvements

You'd still have to manually control the total amount of sections in the for loop and make sure you don't make a mistake in labeling sections. One could use the totcount package to register the total amount of sections present in the document, however I couldn't figure out how to make it work in sync with the pgffor package and ran out of time for today.

I'd still opt for the \tableofcontents, but I had some fun with this answer!

1
  • Thank you so much! For now I'll just reference to it, but I will definitely check out using the for-loop, as that looked really cool. The TOC way works as well, just need to figure out how to make it fit into my design. But anyways, thank you so much for your detailed answer! Dec 15, 2016 at 19:20

You must log in to answer this question.

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