5

Is it possible to use lists WITHIN section headings, subsection headings, etc.? I wanted to do so like

\documentclass[11pt]{scrartcl}
\usepackage{enumerate}
%...
\begin{document}

\section{My three favorite flowers are:
 \begin{enumerate}
  \item Roses
  \item Daysies
  \item Violets
 \end{enumerate}
Now I will tell you stuff about them}

\end{document}

but it doesn't compile. Error is:

Argument of \@sect has an extra }.
<inserted text> 
                \par 
Joseph Wright
  • 259,911
  • 34
  • 706
  • 1,036
Josephus
  • 117
  • What do you mean "it doesn't compile"? What is the error message you receive? Can you provide an MWE starting at \documentclass{...} and ending with \end{document} please? – darthbith Jun 16 '14 at 15:22
  • 6
    And why exactly do you want this? – daleif Jun 16 '14 at 15:22
  • 1
    you mean within section headings; please change the text of your title and the description to make this clear. (and, like daleif, i wonder why you want this.) – barbara beeton Jun 16 '14 at 15:29
  • If you're just after the formatting of the sectional headings, then it's more conceivable. The reason for the comment-questions thus far is because \sections place their arguments in the Table of Contents (if you use it, and is therefore fragile), and it would just seem odd for a document to contain an enumeration/list in the ToC. Also, the formatting is quite excessive to distinguish it from the rest of the text... – Werner Jun 16 '14 at 15:32
  • 5
    Section titles should be as short as possible, without hindering comprehension. An enumerated list in a section title is out of question, in my opinion. – egreg Jun 16 '14 at 15:35
  • 1
    I know it is very odd to do something like that. There are definately better solutions to do this, but I wanted to make an written report ("Ausarbeitung") which answers a great number of specific questions. Most of those questions have lists in them, and I wanted to cite them in the sections, so they are easy to find with the table of contents. @Werner Your comment gave me the idea to use
    \section[Name in Table of Contents]{...}
    
    

    Apparently LaTeX did try to put the list in the ToC, which understandably didn't work.

    – Josephus Jun 16 '14 at 15:48
  • I find it more interesting that you need this, rather than how it is achieved. Can you perhaps provide a "real" example of where this list-in-section might make sense? – kabZX May 02 '16 at 08:47

2 Answers2

6

The argument of sectional units are fragile and therefore can only contain a limited number of things, unless you're careful. A way out of your situation - against all common uses - is to keep your list inside the section, but provide an alternative "floating argument". This is provided by the optional argument:

enter image description here

\documentclass{scrartcl}
\begin{document}

\section[My three favourite flowers]{My three favourite flowers are:
 \begin{enumerate}
  \item Roses
  \item Daisies
  \item Violets
 \end{enumerate}
Now I will tell you stuff about them}

\end{document}

If, however, you're only after the sectional unit font, then you can define that and use it accordingly:

enter image description here

\documentclass{scrartcl}
\makeatletter
\newenvironment{SECTION}
  {\sectfont\size@section\noindent\ignorespaces}% \begin{SECTION}
  {}% \end{SECTION}
\makeatother
\begin{document}

\begin{SECTION}
My three favourite flowers are:
 \begin{enumerate}
  \item Roses
  \item Daisies
  \item Violets
 \end{enumerate}
Now I will tell you stuff about them
\end{SECTION}

\end{document}

You could even add the section number to it by perhaps using

\makeatletter
\newenvironment{SECTION}
  {\refstepcounter{section}%
   \sectfont\size@section\noindent%
   \thesection\quad\ignorespaces}% \begin{SECTION}
  {}% \end{SECTION}
\makeatother

Of course, this would remove all sectional functionality, but I'm not sure whether this is required in your instance.


To match Steven's stack, you can also use this definition:

enter image description here

\documentclass{scrartcl}
\begin{document}

\tableofcontents

\section{\protect\tabular[t]{@{}l}
  My three favourite flowers are: \\
  ~~1. Roses \\
  ~~2. Daisies \\
  ~~3. Violets \\
  Now I will tell you stuff about them
  \protect\endtabular}

\end{document}

The \protection allows for safer travel of fragile arguments.

Werner
  • 603,163
  • It works! Thank you very much for your time and effort, your different ways of accomplishing my goal, and your clean, structured, and educational writing. – Josephus Jun 16 '14 at 18:02
2

You can fake it with a stack:

\documentclass[11pt]{scrartcl}
\usepackage{enumerate}
\usepackage[usestackEOL]{stackengine}
\begin{document}
\tableofcontents

\section{\Longunderstack[l]{
My three favorite flowers are:\\
  ~~1. Roses\\
  ~~2. Daysies\\
  ~~3. Violets\\
Now I will tell you stuff about them
}}
Does it work?
\section{Blah Blah}
More stuff
\end{document}

enter image description here

  • This is magnificent! Unfortunatley I don't have the package in TeXLive 2012. "LaTeX Error: File `stackengine.sty' not found." Do I need to use a newer version? – Josephus Jun 16 '14 at 16:10
  • 1
    @Josephus You can download the sty file and documentation at http://ctan.org/pkg/stackengine – Steven B. Segletes Jun 16 '14 at 16:13