I am trying to achieve the same as this post: Remove newline *before* \section But the problem is that with the suggested solution the section information cannot be used in the header. Is there any way that I can remove the newline before a subsection and at the same time keep the section information for the header? I need a running header with the first and last section and subsection information.

Basically I'm trying to achieve a combination of this: No newline before section, preserve header info

And this: Chapters and verses of current page in header

  • Welcome to TeX.Stackexchange! Can you show us a minimal working example (MWE) that includes how you use your header? – samcarter Apr 17 '17 at 15:13
  • This sounds like a very odd requirement. Why do you want to do this? – Ulrike Fischer Apr 17 '17 at 15:17
  • Just edited the question with more details. – ImAsking Apr 17 '17 at 15:38
  • Sorry I'm new to Latex so I don't have a MWE. Just trying to get ideas from the links I've added. – ImAsking Apr 17 '17 at 15:52
  • I did understand what you want, but why do you want it? A section title in the middle of running text is very unusual and I suspect that you actually want something different. – Ulrike Fischer Apr 17 '17 at 18:19

I think you want something like this, the key is to use \markright (or \markboth or one of the other mark commands) to leave a mark on the page, the page heading can then pick up the first and last mark on the page and use accordingly. In the standard classes \section uses \markright (with chapter level marks using the left mark) so I did the same here, defining a simple \section that uses a counter and leaves a mark but no optional handling or star form, and very little heading formatting

enter image description here

\documentclass{report}

\usepackage[paperheight=8cm,paperwidth=7cm, margin=2cm]{geometry}

\pagestyle{headings}

\renewcommand\section[1]{%
\refstepcounter{section}%
\textsection\thesection\markright{#1}~\textit{#1} %
}

\begin{document}

%\chapter{zzz} omit this as page heading is open on chapter start pages by default
\refstepcounter{chapter}

\section{Start} something about the beginning \section{This} and a bit more
\section{That} A longer section about something that has more than one paragraph.

It seems a bit odd to have a paragraph more distinguished than a section heading, so perhaps that is not needed. \section{Then} and sections will always be inline.

\section{Later} or at the start of a paragraph.

\section{Second Start} something about the beginning \section{Second This} and a bit more
\section{Second That} A longer section about something that has more than one paragraph.

It seems a bit odd to have a paragraph more distinguished than a section heading, so perhaps that is not needed. \section{Second Then} and sections will always be inline.

\section{Second Later} or at the start of a paragraph.

\section{Third} Is surprisingly different to the first two.
\end{document}

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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