0

I'd like to redefine \subsection. The reason is twofold: 1) it appears to be preceded by a built-in \parskip and this is too much of a lost space for me; 2) I'd like to have the line continued with additional text. I tried this:

 \renewcommand{\subsection}[1]{\texttt{#1}}

and this works, except when I use \subsection* to prevent numbering.

Another question: is there a place online where I can find how \subsection is defined, in the first place.

Thank you

  • you do not need to redefine \subsection the spacing and font and whether the following text starts a new paragraph or follows the heading may all be specified in the section parameters either directly or using a package such as secsty – David Carlisle Jun 26 '18 at 14:44
  • 2
    \subsection will be defined in the document class that you are using (but you have not said which) article.cls for example. – David Carlisle Jun 26 '18 at 14:45
2

IMO our approach is somehow biased.

1) it appears to be preceded by a built-in \parskip and this is too much of a lost space for me;

There is no parskip, it's another length (see below)

2) I'd like to have the line continued with additional text.

This is the usual behavior of \paragraph and \subparagraph

In standard LaTeX, \section and all lower level sectioning commands are defined in terms of the internal LaTeX generic command \@startsection as you can see wit the command \meaning\section in the body text.

In book class (10pt), you will get something like :

 \long macro:->\@startsection {section}{1}{\z@ }{-3.5ex \@plus
-1ex \@minus -.2ex}{2.3ex \@plus .2ex}{\normalfont \Large \bfseries }

What you need is :

  1. reduce the first skip (4th argument) to something like {-1.5ex \@plus-0.7ex \@minus -.2ex} (keep the glue and signs)
  2. change the sign of the second skip (5th argument) with something like {-2ex \@plus -.1ex}

It can be done with \renewcommand, with titlesec packagge or with etoolbox's patchcmd:

\patchcmd{\section}{{-3.5ex \@plus -1ex \@minus -.2ex}}{{-1.5ex \@plus-0.7ex \@minus -.2ex}}{\typeout{smaller skip OK}}{\typeout{smaller skip  failed}}%
\patchcmd{\section}{{2.3ex \@plus .2ex}}{{-2ex \@plus -.1ex}}{\typeout{same line OK}}{\typeout{same line failed}}%

EDIT : patching \subsection The \patchcmd replaces ith 2nd argument by the 3rd one. Clearly the skip defined in standard class for \subsection is smaller than for \section. Therefore the second argument of \patchcmd must be read in the \meaning\subsection output.

An example of patching \subsection is (again for book, 10pt) :

\patchcmd{\subsection}{{-3.25ex\@plus -1ex \@minus - .2ex}}{{-1.5ex \@plus-0.7ex \@minus -.2ex}}{\typeout{spacing subsec OK}}{\typeout{spacing subsec failed}}%
\patchcmd{\subsection}{{1.5ex \@plus .2ex}}{{-2ex \@plus -.1ex}}{\typeout{same line subsec f}}{\typeout{same line subsec failed}}%

resulting in (both patched \section and \subsection) :

enter image description here

|improve this answer|||||
  • Thank you, jhor. My concern was more with \subsection than section. I tried following blindly in your footsteps: <pre>\patchcmd{\subsection}{{2.3ex \@plus .2ex}}{{-2ex \@plus -.1ex}}{\typeout{same line ss OK}}{\typeout{same line ss failed}}% </pre> But it did not work – Alexander Bogomolny Jul 4 '18 at 1:08
  • I have edited my post to provide the patching of \subsection. Of course: - the patching of \section and \subsection are independent - it is up to you to choose the value of the 3rd argument (keeping it negative for run-in title, but unneeded glue) - if you use another class, you will have to look at the definition of \subsection to ensiure that it is still defined on the basis of \@startsection and verify the values of the initial skip (2nd argument). – Jhor Jul 6 '18 at 13:12

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.