Text FormattingRemoving Spacing before Chapter with titlesec causes errors

Information and discussion about LaTeX's general text formatting features (e.g. bold, italic, enumerations, ...)
Post Reply
lvlanson
Posts: 2
Joined: Sun Mar 07, 2021 4:12 pm

Removing Spacing before Chapter with titlesec causes errors

Post by lvlanson »

Hey there,

I am trying to remove the spacing before the chapter. I have come across quite a few solutions.

I am trying to put this command into the configuration, using titlesec.

Code: Select all

\usepackage[compact]{titlesec}
\renewcommand{\abovechapterskip}{\vspace*{10pt}}
For each use of \section I get an error.

Code: Select all

! Missing number, treated as zero.<to be read again>} \section{TEXT}
! Illegal unit of measure (pt inserted). <to be read again> \section{TEXT}
The latex code at the concerning looks like this

Code: Select all

\chapter{Grundlagen}
\label{grundlagen}
\section{Erklärende Begriffe}
\label{sec:begriffe}
There is some problem with titlesec and the use of section. Help is greatly appreciated.

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p

Ijon Tichy
Posts: 640
Joined: Mon Dec 24, 2018 10:12 am

Removing Spacing before Chapter with titlesec causes errors

Post by Ijon Tichy »

titlesec does not provide a command \abovechapterskip. So it seems you are using a class or another package, that provides this command. Maybe titlesec is not compatible with that class or package. So please show us a Infominimal working example not only some code snippets.
Sorry, but I can no longer participate here as the administrator is trampling on my wishes on one of his other platforms. :cry:
lvlanson
Posts: 2
Joined: Sun Mar 07, 2021 4:12 pm

Removing Spacing before Chapter with titlesec causes errors

Post by lvlanson »

This is the template I have used, so these are the settings basically.

Code: Select all

%Dokumentklasse
\documentclass[a4paper,12pt]{scrreprt}
\usepackage[left= 2.5cm,right = 2.5cm, bottom = 4 cm, top = 3 cm]{geometry}
%\usepackage[onehalfspacing]{setspace}
% ============= Packages =============

% Dokumentinformationen
\usepackage[
	pdftitle={XXXXXXXXXX},
	pdfsubject={},
	pdfauthor={XXXXXXXXXX},
	pdfkeywords={},	
	hidelinks
]{hyperref}


% Standard Packages
\usepackage[utf8]{inputenc}
\usepackage[ngerman]{babel}
\usepackage[T1]{fontenc}
\usepackage{graphicx, subfig}
\graphicspath{{img/}}
\usepackage{fancyhdr}
\usepackage{lmodern}
\usepackage{color}
\usepackage{float}

\usepackage[backend = biber,
			bibencoding = utf8,
			%style = ieee
			style = authoryear
			%style = authortitle,
			%style = alphabetic,
			]{biblatex}

\addbibresource{biblio.bib}
\usepackage{listings}

\lstdefinestyle{Python}{
    language        = Python,
    basicstyle      = \ttfamily,
    keywordstyle    = \color{blue},
    stringstyle     = \color{codegreen},
    commentstyle    = \color{burgundy}\ttfamily
}

\lstset{
    frame       = single,
    numbers     = left,
    showspaces  = false,
    xleftmargin = 0.7cm,
    showstringspaces    = false,
    captionpos  = t,
    caption     = \lstname,
    tabsize 	  = 2,
    literate={\ \ }{{\ }}1
}

\def\inline{\lstinline[basicstyle=\ttfamily,keywordstyle={}]}

\setlength{\parindent}{0pt}

\setlength\parskip{0.8em} 

\pagestyle{fancy}
%
\lhead{}
\chead{}
\rhead{\slshape \leftmark}
%
\lfoot{}
\cfoot{\thepage}
\rfoot{}
%%
\renewcommand{\headrulewidth}{0.4pt}
\renewcommand{\footrulewidth}{0pt}

\begin{document}
%Seiten ohne Kopf- und Fußzeile sowie Seitenzahl
\pagestyle{empty}

\chapter{Foundation}
\label{foundation}
\section{Terminology}
\label{sec:term}
Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. \parencite[vgl.][S.71]{tanenbaum2016}.
Bartman
Posts: 369
Joined: Fri Jan 03, 2020 2:39 pm

Removing Spacing before Chapter with titlesec causes errors

Post by Bartman »

The KOMA classes and the titlesec package offer tools to set the output of the structure commands. As the two are not coordinated with one another, this leads to problem spots as expected.

Have a look at section 21.8. Sections in the documentation of the used class.

Some off topic hints:

Read issue 28 in ltnews on CTAN on the subject of UTF-8.

hyperref should, with a few exceptions, be the last package to be loaded.

Note that so-called information entries (section 3), if they are needed, should be added after loading the package with the help of the \hypersetup command.

You should also read section 21.6. "Paragraph Indention or Gap" and visit the chapter about the adaption of page headers and footers.
Post Reply