3

How do you embed subsection headings in text like in the the below picture? In most standard latex templates, there would be a gap

1.2 Weil's conjecture for function fields

In this section...

which I'm trying to avoid because I think it makes things cluttered. I would still like there to be a gap for section headings, and for there to be a small space before subsection headings, as in the below picture.

enter image description here

Edit: as requested, here is a minimal working example showing the problem:

\documentclass[12pt]{article}
\begin{document}

\section{Section}

Text A

\subsection{Subsection}

There are two problems with this working example: the subsection is not part of this paragraph (and the letters are not the same size as the letters here), and the gap between Text A and the subsection is too large.

\end{document}

and a picture of what comes out when I put this through TeXmaker:

enter image description here

I am happy to change the document class I'm using.

3
  • Could you please add a small minimal working example (MWE) showing which docuentclass ou currently use?
    – leandriis
    Dec 21, 2019 at 10:46
  • You seem to be using amsart rather than article.
    – egreg
    Dec 21, 2019 at 10:56
  • @egreg If you make that comment an answer I'll accept it, thanks so much!
    – Pulcinella
    Dec 21, 2019 at 10:58

3 Answers 3

2

If you want to reproduce the output in the picture, use amsart.

\documentclass[12pt]{amsart}

\newtheorem{theorem}{Theorem}[section]
\theoremstyle{definition}
\newtheorem{remark}[theorem]{Remark}

\begin{document}

Some nonsense words some nonsense words some nonsense words
some nonsense words some nonsense words some nonsense words
some nonsense words some nonsense words some nonsense words
some nonsense words.

\section{Section title}

Some nonsense words some nonsense words some nonsense words
some nonsense words some nonsense words some nonsense words
some nonsense words some nonsense words some nonsense words
some nonsense words.

\subsection{Subsection title}

Some nonsense words some nonsense words some nonsense words
some nonsense words some nonsense words some nonsense words
some nonsense words some nonsense words some nonsense words
some nonsense words.

\begin{theorem}
A theorem statement. A theorem statement. A theorem statement.
A theorem statement. A theorem statement.
\end{theorem}

\begin{remark}
A remark. A remark. A remark. A remark. A remark.
\end{remark}

Some nonsense words some nonsense words some nonsense words
some nonsense words some nonsense words some nonsense words
some nonsense words some nonsense words some nonsense words
some nonsense words.

\subsection{Another subsection title}

Some nonsense words some nonsense words some nonsense words
some nonsense words some nonsense words some nonsense words
some nonsense words some nonsense words some nonsense words
some nonsense words.

\end{document}

enter image description here

4

In article (without packages) the sectioning macros are all using \@startsection internally. \@startsection takes 6 arguments which control the appearance of a section title:

\@startsection
  {<sectioning name>}
  {<sectioning level>}
  {<horizontal indent from left>}
  {<vertical skip pre>}
  {<skip post>}
  {<font choice>}

While most of those arguments are pretty self-explanatory in the above, two of them behave somewhat special:

  • <vertical skip pre> decides whether the paragraph after the heading will be indented or not. If this is positive or 0 the following paragraph will be indented normally, if this is negative the indentation will be suppressed. In either way the absolute value of this will be used for the vertical skip.

  • <skip post> controls whether the heading will be displayed as a run-in heading, if this is positive it will behave as a vertical skip after the heading and the heading will be displayed. If it is negative or 0 the heading will be a run-in heading and this will be the horizontal skip between the heading and the text in the same line.

So with that out of the way, we can now redefine \subsection to be formatted as a run-in heading.

\renewcommand\subsection
  {%
    \@startsection
      {subsection}
      {2}
      {\z@}
      {3.25ex \@plus 1ex \@minus .2ex}
      {-1em}
      {\normalfont\normalsize\bfseries}%
  }

If we start this formatting on the \subsection level, we should also redefine \subsubsection in the same way. A complete document doing those redefinitions:

\documentclass[]{article}

\makeatletter
\renewcommand\subsection
  {%
    \@startsection
      {subsection}
      {2}
      {\z@}
      {3.25ex \@plus 1ex \@minus .2ex}
      {-1em}
      {\normalfont\normalsize\bfseries}%
  }
\renewcommand\subsubsection
  {%
    \@startsection
      {subsubsection}
      {3}
      {\z@}
      {3.25ex \@plus 1ex \@minus .2ex}
      {-1em}
      {\normalfont\normalsize\bfseries}%
  }
\makeatother

\usepackage{duckuments}

\begin{document}
\section{This is a section}\blindduck
\subsection{This is a subsection}\blindduck
\subsubsection{This is a subsubsection}\blindduck
\paragraph{This is a paragraph}\blindduck
\end{document}

enter image description here

2

With titlesec and article:

enter image description here

\documentclass[12pt]{article}

\usepackage{titlesec}
\titleformat{\subsection}[runin]{\normalsize\bfseries}{\thesubsection}{5pt}{}

\begin{document}

\section{Section}

Text A

\subsection{Subsection}

There are two problems with this working example: the subsection is not part of this paragraph (and the letters are not the same size as the letters here), and the gap between Text A and the subsection is too large.

\end{document}

You must log in to answer this question.

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