3

I have a formal, legal document with line numbering and many sections. I have defined a custom enumerate environment which allows to list paragraphs using \S as follows.

\newlist{myenum}{enumerate}{1}
\setlist[myenum]{nosep,label={\textbf{\S\arabic*}}}

The sections are defined using the titlesec package as follows.

\titleformat{\section}[runin]{\normalfont\scshape}{Section \thesection. }{0em}{}[\newline]

After a \section command, I usually have some introductory text and then a myenum environment which starts on a new line. However, in some cases there is no introductory text. But then, unfortunately the custom enumeration starts one line lower than it should because it inserts an extra newline before the enumeration.

How can I define a custom enumeration environment which does NOT insert a newline before the first item?

See the MWE below. This question could also be stated as: How can I define a custom enumeration environment which has only the first item inline, and otherwise behaves as usual? Please note that the line numbers need to work out properly, i.e. just introducing negative spacing cannot be the solution.

Note further that one could just define a second title class \othersection and remove the \newline option from the title format to solve the spacing issue. However, I need the section numbering and cross-referencing mechanisms to work continuously, and the titlesec package requires each title class to have its own counter. Maybe there is an alternate solution via this approach, but I have not been able to find it.

Screenshot of MWE

\documentclass{article}

\usepackage{titlesec}
\titleformat{\section}[runin]{\normalfont\scshape}{Section \thesection. }{0em}{}[\newline]

\usepackage{enumitem}
\newlist{myenum}{enumerate}{1}
\setlist[myenum]{nosep,label={\textbf{\S\arabic*}}}

\usepackage{lineno}
\leftlinenumbers
\linenumbers

\begin{document}

\section{First Section}
First section introductory text.
\begin{myenum}
    \item First item
    \item Second item   
\end{myenum}

\section{Second Section Without Intro Text}
\begin{myenum}
    \item First item after extra line (unwanted!)
\end{myenum}

\end{document}
1
  • Actually, they add \par, not \newline. May 3, 2020 at 14:16

1 Answer 1

2

The problem is in using runin with \newline afterwards. Drop them and act on spacings instead.

\documentclass{article}

\usepackage{titlesec}
\usepackage{enumitem}
\usepackage{lineno}

%% titlesec
\titleformat{\section}
  {\normalfont\scshape}
  {Section \thesection. }
  {0em}
  {}
\titlespacing*{\section}% * means no indent after the title
  {0pt}% left
  {*4}% above
  {0pt}% below

\newlist{myenum}{enumerate}{1}
\setlist[myenum]{nosep,label={\textbf{\S\arabic*}}}

\leftlinenumbers
\linenumbers

\begin{document}

\section{First Section}
First section introductory text.
\begin{myenum}
    \item First item
    \item Second item   
\end{myenum}

\section{Second Section Without Intro Text}
\begin{myenum}
    \item First item after extra line (unwanted!)
\end{myenum}

\end{document}

enter image description here

3
  • Hi, thanks a lot! I didn't know that titlespacing could handle this. I actually do indent the first line after a \section, and just taking away the star from the command doesn't indent the normal text afterwards. How could I add this back in?
    – 1Darco1
    May 3, 2020 at 14:50
  • \parindent doesn't affect this indentation. I'm actually unsure what caused the indent in my main document before – I always thought it was due to runin but my MWE above clearly shows that's not the case.
    – 1Darco1
    May 3, 2020 at 15:06
  • 1
    @1Darco1 If you use \titlespacing instead of \titlespacing* you do get an indent of width \parindent. If your document modifies it…
    – egreg
    May 3, 2020 at 15:53

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.