GeneralHow do I suppress newline after a subsection heading?

LaTeX specific issues not fitting into one of the other forums of this category.
quickq
Posts: 17
Joined: Wed Oct 13, 2010 8:14 pm

How do I suppress newline after a subsection heading?

Post by quickq »

Hi, I would like to do this
2.3 Explanation of...
2.3.1 Motivation. Having seen that...

i.e. the subsection 2.3.1 Motivation does not have a newline following it (but is only bold), unlike the section heading "Explanation of...". I've seen this done before. How do I do this with the article document type? Thank you.

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p

frabjous
Posts: 2064
Joined: Fri Mar 06, 2009 12:20 am

How do I suppress newline after a subsection heading?

Post by frabjous »

You can do that sort of thing with the titlesec package. You should probably read its documentation.

I'm a bit confused by your sample text, though, since in the article class there are no chapters, so a subsection would typically just be "2.3" and not "2.3.1" -- what is the extra number there? But maybe this example here will give you the basic idea.

Code: Select all

\documentclass{article}
\usepackage{lipsum} % for generating filler text
\usepackage{titlesec}
\titleformat{\subsection}[runin]% runin puts it in the same paragraph
       {\normalfont\bfseries}% formatting commands to apply to the whole heading
       {\thesubsection}% the label and number
       {0.5em}% space between label/number and subsection title
       {}% formatting commands applied just to subsection title
       [.]% punctuation or other commands following subsection title
\begin{document}
        \section{This is a section}
        \subsection{This is a subsection}
        \lipsum[1]% (filler text)
\end{document}
result:
runin.png
runin.png (13.62 KiB) Viewed 28436 times
Again, it would be a good idea to read the package documentation.
quickq
Posts: 17
Joined: Wed Oct 13, 2010 8:14 pm

Re: How do I suppress newline after a subsection heading?

Post by quickq »

thanks, I might get back with more questions but this is basically working. (you're right, I messed up my numbering in my example).
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

How do I suppress newline after a subsection heading?

Post by localghost »

If this problem is solved now, please be so kind and mark the topic accordingly as clearly written in Section 3 of the Board Rules (to be read before posting). Otherwise please tell us what is missing. Please keep that in mind for the future so that further reminders will not be necessary.


Best regards and welcome to the board
Thorsten
quickq
Posts: 17
Joined: Wed Oct 13, 2010 8:14 pm

How do I suppress newline after a subsection heading?

Post by quickq »

Hi,

I said it was basically working. It is not quite what I wanted, as it has an extra newline that I would like to eliminate.

Here is example of how I would like it to look and how it looks following your suggestion

Code: Select all

\documentclass{article}
\usepackage{titlesec}
\titleformat{\subsection}[runin]% runin puts it in the same paragraph
       {\normalfont\bfseries}% formatting commands to apply to the whole heading
       {\thesubsection}% the label and number
       {0.5em}% space between label/number and subsection title
       {}% formatting commands applied just to subsection title
       [.]% punctuation or other commands following subsection title
\begin{document}
        \section{Permutations}
        \subsection{Original version}
        ``The quick brown fox jumps over the lazy dog.''  This version ...
        \subsection{Modern version}
        ``Over the lazy fox jumps the quick brown dog.''  While in some ways...
        \subsection{Proposed version}
        ``Over the brown, quick, lazy jumps the fox dog.''  The advantages...
\end{document}
And this is how I would like it to look:

Code: Select all

\documentclass{article}
\begin{document}
        \section{Permutations}
        {\bf 1.1. Original version.} ``The quick brown fox jumps over the lazy dog.''  This version ...\\
        {\bf 1.2. Modern version.} ``Over the lazy fox jumps the quick brown dog.''  While in some ways...\\
        {\bf 1.3. Proposed version.} ``Over the brown, quick, lazy jumps the fox dog.''  The advantages...\\
\end{document}
Obviously I don't really want to hand-number the subsections!! This is just how I want it to look... I've seen this done so I still think it's possible, just having some trouble achieving it... Thank you.

p.s. am I using bold correctly? It has the effect I want (the output looks like I want it to) and I'm sure I saw this somewhere, but I wonder if my usage is "correct". Maybe it just "happens to work"
User avatar
gmedina
Posts: 2313
Joined: Wed Jul 11, 2007 11:45 pm

How do I suppress newline after a subsection heading?

Post by gmedina »

Hi quickq,

you can use \titlespacing* to control the spacing before and after the title:

Code: Select all

\documentclass{article}
\usepackage{titlesec}
\titleformat{\subsection}[runin]% runin puts it in the same paragraph
       {\normalfont\bfseries}% formatting commands to apply to the whole heading
       {\thesubsection}% the label and number
       {0.5em}% space between label/number and subsection title
       {}% formatting commands applied just to subsection title
       [.]% punctuation or other commands following subsection title
\titlespacing*{\subsection}{0pt}{0pt}{0pt}

\begin{document}
        \section{Permutations}
        \subsection{Original version}
        ``The quick brown fox jumps over the lazy dog.''  This version ...
        \subsection{Modern version}
        ``Over the lazy fox jumps the quick brown dog.''  While in some ways...
        \subsection{Proposed version}
        ``Over the brown, quick, lazy jumps the fox dog.''  The advantages...
\end{document}
1,1,2,3,5,8,13,21,34,55,89,144,233,...
quickq
Posts: 17
Joined: Wed Oct 13, 2010 8:14 pm

How do I suppress newline after a subsection heading?

Post by quickq »

Thank you. Almost there... :) Now I get:
1.1 Original version.In the beginning... ----- But I still want:
1.1. Original version. In the beginning...

(period after numbering / space after name of subsection)
Sorry I'm being so detail-oriented, I just want a pop-in replacement for the formatting I'm doing by hand (including hand-numbering).
I'm trying to figure out how to add these last two things, but I'm having trouble...
User avatar
frabjous
Posts: 2064
Joined: Fri Mar 06, 2009 12:20 am

How do I suppress newline after a subsection heading?

Post by frabjous »

The last argument to titlespacing sets the horizontal spacing after the title:

Code: Select all

\titlespacing*{\subsection}{0pt}{0pt}{0.5em}
(If 0.5em is too wide or too narrow, change it to whatever you might want instead.)

To add a period at the end of the number change the line that reads:

Code: Select all

 {\thesubsection}% the label and number
to

Code: Select all

 {\thesubsection.}% the label and number

Please read the package documentation, as I have already suggested. Then you could answer these questions for yourself.
quickq
Posts: 17
Joined: Wed Oct 13, 2010 8:14 pm

How do I suppress newline after a subsection heading?

Post by quickq »

I'm sorry I haven't been reading all the documentation. I just learned latex three and a half days ago, and for the past three days have been doing nothing but formatting my article, without any regard for the content. It is really hard for me to understand documentation because I don't have my head around all of the standard vocabulary of latex. I just want to do it right and finally get started on working on the content.

On the point you just helped me with, there is one thing that I had in my original, which I did not mention. In certain places I had a "quote" environment (if I'm even using the word environment right) around my paragraphs, but wanted to continue having them numbered. Now that I've followed your advice,
\begin{quote}
\subsection{whatever}
blah blah
\end{quote}
doesn't work the way
\begin{quote}
{\bf 1.2. whatever.} blah blah\\
\end{quote}
had. I don't want to change the whole style of the title (if I'm even using the vocabulary right in this sentence) throughout the document, i just want it inside a quote environment in one place. Is this possible or should I just give up?

I'm sorry, I can't understand http://tug.ctan.org/tex-archive/macros/ ... tlesec.pdf yet.

Everything here is really, really hard for me and I am just a beginner. Thank you for your patience.
quickq
Posts: 17
Joined: Wed Oct 13, 2010 8:14 pm

How do I suppress newline after a subsection heading?

Post by quickq »

Well, this seems, empirically, to have the same effect as "quote":

Code: Select all

\begin{center}
\begin{minipage}[]{0.85\linewidth}
...
\end{center}
\end{minipage}
(except it actually works for what I'm doing) so I guess it'll have to do...
Post Reply