# Is it possible to have section titles inside paragraphs?

Is there a way to have section titles that are inside paragraphs, especially when using titlesec package?

The runin style and others cause a paragraph break after the input line. What I am aiming for is just a normal paragraph that has titles inside itself.

• You could use \vspace{-4ex}, for example, to remove the space between the previous text and the section name. Other people will probably have more sophisticated answers.
– Mars
Aug 28, 2013 at 4:47

Disclaimer This is a way to go but please don't do that since the output is not really reader-friendly.

If you do not want to modify anything else in the section titles style, you can add the following code

\documentclass{article}
\usepackage{blindtext}
\usepackage{hyperref}

\makeatletter
\newcommand\gobblepars{%
\@ifnextchar\par%
{\expandafter\gobblepars\@gobble}%
{}}
\makeatother

\newenvironment{mysec}[1]{%
\stepcounter{section}%
{\bfseries\noindent\thesection\hspace{0.5em} #1\hspace{0.5em}}%
\sectionmark{#1}}%
{\gobblepars \hspace{0.5em}}

\begin{document}

\begin{mysec}{First Section Title}
\blindtext
\end{mysec}
\begin{mysec}{Second Section Title}
\blindtext
\end{mysec}

\end{document}


The gobblepars command is coming from this answer.

You will get this kind of output

NOTE I am not entirely sure about the part for the sectionmark and all kind of advise would be welcomed. Concerning the TOC it seems to work properly as well as the section numbers.

• I already answered this question in a similar way (I've deleted it), but the OP wants (I don't know why) no line break between two sections... I'm undeleting it for a few minutes, so you will see what he/she answered. Aug 30, 2013 at 8:50
• @karlkoeller See my edit. It should better fit the will of the OP. Aug 30, 2013 at 10:31
• Please add in the answer: "Please don't do that"... BTW: I forgot to delete mine again. Done now. Aug 30, 2013 at 10:36
• @LudovicC. I came up with a similar thing but it really did not work in all the needed aspects. Your answer does everything correctly, including sectionmark. Thank you! Regarding reader friendliness, I use this kind of titling to provide verse numbers as superscripts so it's not such a huge aesthetic problem. Aug 31, 2013 at 8:43
• @karlkoeller Thanks! And you know I am not at all a guru in LaTeX, I just try to bring my contribution to this amazing website where I got so much for my previous projects. If I could help only one person that would already be nice in my opinion. Sep 1, 2013 at 20:27