2

I defined a command that I use to add some levels of section headers (there are more of those, with different properties, but I show only one here):

\newcommand{\myssssection}[1]{{\addcontentsline{toc}{subsubsection}{\hspace{1.6cm}{#1}}}%
                              {\vspace{1ex}\noindent\normalfont\large\sffamily{\bfseries{#1}}\newline}}

Now what I would like to do is to suppress the indentation of the first paragraph that follows, similar to the way the regular \section commands presumably does it.

I understand I can add \noindent in from of the first paragraph, but it would be nicer to include this in the pseudo-section command that I defined.

6
  • 2
    is there any reason not to use the latex section defining commands such as \@startsection here so that tables of contents handling and control of indentation were automatic? Mar 21, 2017 at 20:22
  • Have a look at the noindentafter package.
    – user103221
    Mar 21, 2017 at 21:00
  • Do you use a KOMA-class? If so you can use \DeclareSectionCommand Mar 21, 2017 at 21:34
  • apart from suppressing indentation a section command would normally be expected to prevent page breaks after the heading or after just one line of the next paragraph Mar 21, 2017 at 21:36
  • Ok, \@startsection fixes this, I was not aware of this command. However, I don't know how to add the toc entry for this sectioning, the way I like it (indented).
    – user52366
    Mar 22, 2017 at 19:37

1 Answer 1

1

There are a number of things that sectional units do that is not covered properly in your definition of \myssssection. Sections

  • start a new paragraph;
  • insert a ToC-related entry after setting the heading;
  • ensures there is no (page) break between the section heading and the first line of the following paragraph;
  • insert an appropriate mark (in the header);
  • typically prevent indentation of the following paragraph.

All of the above is implemented when you use \@startsection. Here's how one can do just that:

enter image description here

enter image description here

\documentclass{article}

\usepackage{lipsum,pgffor}% Just for this example
\usepackage{etoolbox}

\newcounter{subsubsubsection}[subsubsection]
\renewcommand\thesubsubsubsection{\thesubsubsection.\arabic{subsubsubsection}}
\renewcommand\theparagraph{\thesubsubsubsection.\arabic{paragraph}}% Optional, if you're using numbered \paragraphs

\makeatletter

\newcommand\subsubsubsection{\@startsection{subsubsubsection}{4}{\z@}%
  {-1ex \@plus.2ex \@minus.2ex}% <space before>
  {1ex \@plus.2ex \@minus.2ex}% <space after>
  {\normalfont\large\bfseries\sffamily}}
% \patchcmd{<cmd>}{<search>}{<replace>}{<success>}{<failure>}
\patchcmd{\paragraph}{{paragraph}{4}}{{paragraph}{5}}{}{}% Demote \paragraph
\patchcmd{\subparagraph}{{subparagraph}{5}}{{subparagraph}{6}}{}{}% Demote \subparagraph

\newcommand{\subsubsubsectionmark}[1]{}% An appropriate mark

\newcommand{\l@subsubsubsection}{\@dottedtocline{4}{7em}{4em}}
\renewcommand{\l@paragraph}{\@dottedtocline{5}{10em}{5em}}% Shift \paragraph entries one level lower
\renewcommand{\l@subparagraph}{\@dottedtocline{6}{14em}{6em}}% Shift \subparagraph entries one level lower

\makeatother

\setcounter{secnumdepth}{3}% Only number up to \subsubsection, not \subsubsubsection
\setcounter{tocdepth}{4}% Include up to \subsubsubsection in ToC

\begin{document}

% Create a dummy document with all levels of sectional units from \section to \paragraph
\tableofcontents

\foreach \SECTION in {First, Second, Third, Last} {
  \section{\SECTION{} section}\lipsum[1]
  \foreach \SUBSECTION in {First, Second, Third, Last} {
    \subsection{\SUBSECTION{} subsection}\lipsum[2]
    \foreach \SUBSUBSECTION in {First, Second, Third, Last} {
      \subsubsection{\SUBSUBSECTION{} subsubsection}\lipsum[3]
      \foreach \SUBSUBSUBSECTION in {First, Second, Third, Last} {
        \subsubsubsection{\SUBSUBSUBSECTION{} subsubsubsection}\lipsum[4]
        \foreach \PARAGRAPH in {First, Second, Third, Last} {
          \paragraph{\PARAGRAPH{} paragraph}\lipsum[5]
        }
      }
    }
  }
}

\end{document}

References:

5
  • FWIW, \makeatletter\def\section{\@startsection {section}{1}{\z@}{3.5ex plus 1ex minus .2ex}{2.3ex plus .2ex}{\Large\bf}}\makeatother indents the following paragraph. Jan 12, 2022 at 20:09
  • @TorstenBronger: Do you know why?
    – Werner
    Jan 12, 2022 at 20:24
  • No, but I found out that an appended \@afterindentfalse\@afterheading helps. I do not understand those commands, though. Jan 12, 2022 at 21:14
  • Ah, I found it: If the fourth argument to \@startsection is negative, the absolute value is used and the following paragraph is not indented. Magic. Jan 12, 2022 at 21:24
  • @TorstenBronger: As mentioned in Where can I find help files or documentation for commands like \@startsection for LaTeX?, the fourth argument - beforeskip - is used to assess indentation or not after the section heading. If the value (length) of beforeskip is negative, there's no indent. Otherwise, there's an indent. You supplied a positive length (3.5ex plus 1ex minus .2ex, where the default is negative: -3.5ex \@plus -1ex \@minus -.2ex).
    – Werner
    Jan 12, 2022 at 21:24

You must log in to answer this question.

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