How to prevent linebreaks after \subsection or \section

latex

Here I queried how to identify the counters for \subsection and \theorem.

The resulting look would be the same (except for the math-specific things, like the content inside a theorem is put in emphasis) if only there is a way to prevent linebreaks after \subsection.

Is there a way to do this? Thanks.

Best Answer

One way is by using the titlesec package to format the section with 'runin'. Once you've installed the titlesec package for use you can put this in the preamble:

\usepackage{titlesec}

\titleformat{\subsection}[runin]
{\normalfont\large\bfseries}{\thesubsection}{1em}{}

The formatting settings above other than the 'runin' option are the default settings for subsections. Those can of course be modified, e.g., you could take out the '\large' if you wanted the subsection headings to be same size as the theorem headings.