2

I am writing an university report and I have to answer to a series of topics divided in points. I'd like to obtain a header like this 1.1.a,b,c. I have written this command to generate a single subsubsection referring to multiple points:

\documentclass{article}
\usepackage{lipsum}
\newcount\tmp

\newcommand{\multisub}[2][1]{%
\vspace{1.2\baselineskip plus .35\baselineskip minus.07\baselineskip}%
%\vspace{.5em}%
{\bf\thesubsection.%
\tmp=0%
\advance\tmp by 2%
%#1 max num
%#2 text
\loop%
    \advance\tmp by 1%
    \addtocounter{subsubsection}{1}%
    \alph{subsubsection},%
    \ifnum \tmp<#1%
\repeat%
\addtocounter{subsubsection}{1}%
\alph{subsubsection} #2\\%
}%
%    \vspace{.5em}%
\vspace{.8\baselineskip plus .07\baselineskip}%
{\normalfont\normalsize\bfseries}%
}%

\begin{document}
\section{First section}
\subsection{First subsection}
\lipsum[1]
\multisub[2]{First two points}
\lipsum[2]
\end{document}

The result is the following:

enter image description here

As you can see it has the form I'm looking for, but the spacing after the subsubsection header is wrong, as if the space after the header comes only after the first line of text.

How can I solve it? And how can I add this new subsection to the table of contents?

Thanks in advance.

2

Here is how you can define a \multisubsection command for coping with more subsections at a time.

\documentclass[oneside]{book} % oneside just to make a sensible picture
\usepackage{xparse}
\usepackage{kantlipsum}

\newcommand{\normalthesubsection}{%
  \renewcommand{\thesubsection}{\thesection.\alph{subsection}}%
}
\normalthesubsection

% add space for the composite numbers, adapt to your need
% increasing or decreasing 5em
\makeatletter
\renewcommand\l@subsection{\@dottedtocline {2}{3.8em}{5em}}
\makeatother

\ExplSyntaxOn
\NewDocumentCommand{\multisubsection}{mO{#3}m}
 {% #1 = number of subsections to span
  % #2 = optional short title
  % #3 = title
  \tl_clear:N \l_tmpa_tl
  \int_step_inline:nn { #1 - 1 }
   {
    \stepcounter{subsection}
    \tl_put_right:Nx \l_tmpa_tl { \alph{subsection}, }
   }
  \renewcommand{\thesubsection}{\thesection.\l_tmpa_tl\alph{subsection}}
  \subsection[#2]{#3}
  \normalthesubsection
 }
\ExplSyntaxOff

\begin{document}

\frontmatter

\tableofcontents

\mainmatter

\chapter{Title}

\section{Title}

\subsection{First point}

\kant[1]

\multisubsection{3}{Three more points}\label{a}

\ref{a}\kant[2]

\subsection{Another point}

\end{document}

enter image description here

Also \multisubsection{<n>}[Title for the toc]{Title in the document} is supported.

How does this work? When a \multisubsection is called, I step the relevant counter one time less than the argument specifies, collecting the “numbers” (in this case, letters) followed by a comma in \l_tmpa_tl; then I redefine \thesubsection to be as usual, but with the insertion of \l_tmpa_tl before the final number; the \subsection command called in the background will do the final stepping and print the full number. Finally, the standard meaning of \thesubsection is restored.

  • thanks a lot! exactly what I was looking for – Luca C. Dec 28 '18 at 21:56
  • @LucaC. You're welcome. I changed a little the code. A \label command can now be used as usual. Note that you can even call \multisubsection{1}{Title}, so if you later change your mind about some points, you just need to change the number. – egreg Dec 28 '18 at 22:04
  • amazing, I've added your code to my report and works perfectly. May I ask you, why have you called the new command right after its definition? – Luca C. Dec 28 '18 at 22:14
  • @LucaC. That's the initialization for \thesubsection in the required form “Chapter number.Section number.Subsection letter”. Just avoiding code duplication. – egreg Dec 28 '18 at 22:27

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.