Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

How can I prevent a paragraph break before a section heading? To prevent it after, I know that I can use runin like

\titleformat{\section}[runin]{\Large\bf}{\thesection\quad}{0pt}{}

However, how can I prevent before? I want something like:

1. First section heading Text... (no line break here) 2. Second Section Heading Text...


EDIT. I am trying in the following way for \subsection. I created a new command like:

\newcommand{\subsectionnlb}[1]{
   \stepcounter{subsection}
   {\normalfont\bf\thesubsection \hspace{0.3em} #1\hspace{0.3em}}
}

How can I call the formatting of \subsection and apply to the custom command \subsectionnlb?

share|improve this question
1  
If I understood, you want something like 1. First section heading Text... and then comes a section heading without a line break 2. Second Section Heading Text... If so, titlesec package can't do it, because the very \section command internals (namely, as far as I know, \@startsection) definition starts with a \par... –  henrique Jul 2 '11 at 2:22
    
@henrique You are correct. I revised my question. What about a \subsection without break? –  FEQ Jul 5 '11 at 20:57
add comment

1 Answer

up vote 1 down vote accepted

If you don't need to use \section specifically, you can try the following workaround:

\documentclass{scrartcl}
\usepackage{blindtext}
\newcounter{sect}%          Creates a counter to be used in the new section command
\newcommand\Section[1]{%    Defines a new section command:
 \addtocounter{sect}{1}%    Increases counter
 \addcontentsline{toc}{section}{\arabic{sect}.~#1}% Add to table of contents
  {\sectfont% This command is intended to use with scrartcl class; 
%    if not using it you can use any formatting command you wish
  \arabic{sect}.~#1.}}%    Prints "<section number>. <section title>"
\begin{document}
\tableofcontents
\blindtext
\Section{A first section}
\blindtext
\Section{A second section}
\blindtext
\end{document}

EDIT: BTW, this workaround doesn't use (it's actually incompatible with) titlesec package, but I assumed (based on your last comment) that you didn't actually required it.

share|improve this answer
    
Thanks for the answer. Yes, I don't need titlesec, so I deleted it from the title. I was wondering if there is something similar to \sectfont in the article package. –  FEQ Jul 6 '11 at 16:03
    
There isn't --- the definition of \section in article.cls is \newcommand\section{\@startsection {section}{1}{\z@}{-3.5ex \@plus -1ex \@minus -.2ex}{2.3ex \@plus.2ex}{\normalfont\Large\bfseries}}. If you'll use this workaround you can create one with \newcommand{\sectfont}{\bfseries} for example. I don't recommend changing the font size, as the sectioning command will come within the text. –  henrique Jul 6 '11 at 20:32
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.