Hi!
I'm new to latex but have decided to try it out for my master thesis (as many others it seems like). However, the page layout have to look in a certain way and I just can't make it work.
For example, the spacing between the \section{} and the paragraph above should be 16 pt and 4 pts to the one below. At the same time there should be one line separating each paragraph.
I have tried to achieve this by:
\usepackage[compact]{titlesec}
\titlespacing*{\section}{0pt}{16pt}{4pt}
\setlength{\parskip}{\baselineskip}
However, the \baselineskip seems to override the \titlespacing so that the spacing above and below the \section is too long. What would be a better solution to make it look the way it has to?
Page Layout ⇒ Problem getting \titlespacing and \baselineskip work togethe
-
- Posts: 4
- Joined: Tue Aug 10, 2010 2:44 am
NEW: TikZ book now 40% off at Amazon.com for a short time.

Problem getting \titlespacing and \baselineskip work togethe
I think the \parskip amount is added before any paragraph, including the first paragraph of a section, so that when you increase \parskip to a non-zero amount, your command to titlesec adds 4pt after the section title, and then the beginning of the first paragraph adds the \parskip value on top of it. A quick kludge would be to define the last argument to titlespacing to be 4pt minus parskip, e.g.:
Someone might have a cleaner idea, however.
Code: Select all
\usepackage[compact]{titlesec}
\setlength{\parskip}{\baselineskip}
\newlength{\aftersection}
\setlength{\aftersection}{4pt}
\addtolength{\aftersection}{-1\parskip}
\titlespacing*{\section}{0pt}{16pt}{\aftersection}
-
- Posts: 4
- Joined: Tue Aug 10, 2010 2:44 am
Problem getting \titlespacing and \baselineskip work togethe
Thank you!
The code above works fine so I consider it solved. I did the same thing to fix the correct spacing before the section as well, so the final code became:
Nicer ideas are always welcome but I think this is kind of neat 
The code above works fine so I consider it solved. I did the same thing to fix the correct spacing before the section as well, so the final code became:
Code: Select all
\usepackage[compact]{titlesec}
\setlength{\parskip}{\baselineskip}
\newlength{\aftersection}
\setlength{\aftersection}{4pt}
\addtolength{\aftersection}{-1\parskip}
\newlength{\beforesection}
\setlength{\beforesection}{16pt}
\addtolength{\beforesection}{-1\parskip}
\titlespacing*{\section}{0pt}{\beforesection}{\aftersection}

- localghost
- Site Moderator
- Posts: 9202
- Joined: Fri Feb 02, 2007 12:06 pm
Problem getting \titlespacing and \baselineskip work togethe
Marking a topic as solved means to edit the initial post, not the last one. So, please catch up on that as described in the rules.
Best regards and welcome to the board
Thorsten
Best regards and welcome to the board
Thorsten
How to make a "Minimal Example"
Board Rules
Avoidable Mistakes
¹ System: TeX Live 2025 (vanilla), TeXworks 0.6.10
Board Rules
Avoidable Mistakes
¹ System: TeX Live 2025 (vanilla), TeXworks 0.6.10