3

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.

1
  • 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

1 Answer 1

3

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}}%
\addcontentsline{toc}{section}{\thesection \hspace{0.5em} #1}%
\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

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.

6
  • 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.
    – Ludovic C.
    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.
    – Ludovic C.
    Sep 1, 2013 at 20:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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