0

Redefining sections commands with titleclass{page} and titleclass{top} from titlesec results in unwanted white above the headings.

How can this white space removed properly (without eye-tweaking with negative spaces)?

MWE

\documentclass{article}

\usepackage{titlesec}
\usepackage{showframe,lipsum,parskip}

\titleformat{\section}{\bfseries}{\thesection}{1em}{}
\titlespacing*{\section}{0pt}{0pt}{0pt}
\titleclass{\section}{page}

\titleformat{\subsection}{\bfseries}{\thesubsection}{1em}{}
\titlespacing*{\subsection}{0pt}{0pt}{0pt}
\titleclass{\subsection}{top}

\begin{document}

\section{Lorem Ipsum}

\subsection{Dolor sit amet}
\lipsum[1-3]


\section{Some Text}

\subsection{Some more Text}
\lipsum[1-3]

\end{document}
  • 1
    Welcome to TeX SX! Why did you change the class of \section? – Bernard Feb 20 '18 at 20:48
  • Because I want section titles on a dedicated page and subsection titles always on top. The titleclasses page and top were looking like the proper approach. – halifaxone Feb 20 '18 at 20:59
2

Is this what you want?

\documentclass{article}

\usepackage{titlesec}
\usepackage{showframe, lipsum, parskip}
\renewcommand{\ShowFrameLinethickness}{0.3pt}

\titleformat{\section}{\bfseries}{\thesection}{1em}{}
\titlespacing*{\section}{0pt}{-4.5ex}{0pt}
\titleclass{\section}{page}

\titleformat{\subsection}{\bfseries}{\thesubsection}{1em}{}
\titlespacing*{\subsection}{0pt}{-4.5ex}{0pt}
\titleclass{\subsection}{top}

\begin{document}

\section{Lorem Ipsum}

\subsection{Dolor sit amet}
\lipsum[1-3]


\section{Some Text}

\subsection{Some more Text}
\lipsum[1-3]

\end{document} 

enter image description here enter image description here

Edit: This simpler code does not depend on the font size used fir section titles:

\documentclass{extarticle}

\usepackage{titlesec}
\usepackage{showframe, lipsum, parskip}
\renewcommand{\ShowFrameLinethickness}{0.3pt}

\titleformat{\section}{\clearpage\Huge\bfseries\Huge}{\thesection}{1em}{}[\clearpage]

\titleformat{\subsection}{\clearpage\bfseries}{\thesubsection}{1em}{}

\begin{document}

\section{Lorem Ipsum}

\subsection{Dolor sit amet}
\lipsum[1-3]

\subsection{Some more Text}
\lipsum[5-6]

\section{Some Text}

\subsection{Some more Text}
\lipsum[7-10]

\end{document} 

enter image description here

  • Looks like the desired output. Could you elaborate where the 4.5ex white space is coming from? Why is it not supressed with \titlespacing*{...}{0pt}{0pt}{0pt}? Thanks in advance! – halifaxone Feb 21 '18 at 6:35
  • I'm trying your solution with different font sizes now. Bigger sizes (e.g. \Huge) are giving that unwanted white space again. Therefore I'm looking for a general solution, that removes the space without manually tweaking by eye for every font size. – halifaxone Feb 21 '18 at 7:47
  • @halifaxone: Please see my edit. I propose a new, simpler code, without changing the class. – Bernard Feb 21 '18 at 9:26
  • Thanks that solves the problem. However I'm still wondering about the white spaces when using \titleclass{...}{...}. Do you have any idea why they occur? – halifaxone Feb 21 '18 at 9:56
  • No precise idea. It must be hard-coded in titlesec to mimic the defaults of \part and \chapter. There's a similar problem with package titling (used for cuustom \maketitles), which provides the \droptitle length. – Bernard Feb 21 '18 at 10:31

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.