GeneralHow to prevent a newline for a new section

LaTeX specific issues not fitting into one of the other forums of this category.
Post Reply
cool_divya_4u
Posts: 7
Joined: Sun Jul 04, 2010 7:07 pm

How to prevent a newline for a new section

Post by cool_divya_4u »

Folks,

Latex always leaves a line, and text goes on the line below when we create a new section or subsection or subsubsection. Is there a way to prevent this? That is, the text begins on the same line?
Last edited by cool_divya_4u on Sun Jul 04, 2010 8:00 pm, edited 1 time in total.

Recommended reading 2024:

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

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

Stefan Kottwitz
Site Admin
Posts: 10348
Joined: Mon Mar 10, 2008 9:44 pm

Re: How to prevent a newline for a new section

Post by Stefan Kottwitz »

Hi,

LaTeX base classes provide \paragraph and \subaragraph, they produce a run-in heading, they don't cause a line break.
Or do you have to use \section and \subsection? Which document class do you use?

Stefan
LaTeX.org admin
cool_divya_4u
Posts: 7
Joined: Sun Jul 04, 2010 7:07 pm

Re: How to prevent a newline for a new section

Post by cool_divya_4u »

Thanks for your reply. I am using article class, and using \section, \subsection, and \subsubsections for the sections.
User avatar
Stefan Kottwitz
Site Admin
Posts: 10348
Joined: Mon Mar 10, 2008 9:44 pm

How to prevent a newline for a new section

Post by Stefan Kottwitz »

Try this in your preamble:

Code: Select all

\makeatletter
\renewcommand\section{\@startsection {section}{1}{\z@}%
                                   {-3.5ex \@plus -1ex \@minus -.2ex}%
                                   {-1em}%
                                   {\normalfont\Large\bfseries}}
\renewcommand\subsection{\@startsection{subsection}{2}{\z@}%
                                     {-3.25ex\@plus -1ex \@minus -.2ex}%
                                     {-1em}%
                                     {\normalfont\large\bfseries}}
\renewcommand\subsubsection{\@startsection{subsubsection}{3}{\z@}%
                                     {-3.25ex\@plus -1ex \@minus -.2ex}%
                                     {-1em}%
                                     {\normalfont\normalsize\bfseries}}
\makeatother
These are definitions like in the article class except they now produce a run-in heading.

Stefan
LaTeX.org admin
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

How to prevent a newline for a new section

Post by localghost »

Less complicated when using the titlesec package.


Best regard and welcome to the board
Thorsten
cool_divya_4u
Posts: 7
Joined: Sun Jul 04, 2010 7:07 pm

Re: How to prevent a newline for a new section

Post by cool_divya_4u »

By the way, I am using titlesec package to reduce section title fontsize. Can I use the same package to prevent the lines as well? If so, do you mind letting me know?
User avatar
Stefan Kottwitz
Site Admin
Posts: 10348
Joined: Mon Mar 10, 2008 9:44 pm

How to prevent a newline for a new section

Post by Stefan Kottwitz »

If you're already using titlesec, simply state the optional argument runin:

Code: Select all

\titleformat{\section}[runin]{...
Stefan
LaTeX.org admin
Post Reply