Page LayoutProblem getting \titlespacing and \baselineskip work togethe

Information and discussion about page layout specific issues (e.g. header and footer lines, page formats, page numbers).
Post Reply
pansartaxen
Posts: 4
Joined: Tue Aug 10, 2010 2:44 am

Problem getting \titlespacing and \baselineskip work togethe

Post by pansartaxen »

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?

Recommended reading 2024:

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

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

frabjous
Posts: 2064
Joined: Fri Mar 06, 2009 12:20 am

Problem getting \titlespacing and \baselineskip work togethe

Post by frabjous »

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.:

Code: Select all

\usepackage[compact]{titlesec}
\setlength{\parskip}{\baselineskip}
\newlength{\aftersection}
\setlength{\aftersection}{4pt}
\addtolength{\aftersection}{-1\parskip}
\titlespacing*{\section}{0pt}{16pt}{\aftersection}
Someone might have a cleaner idea, however.
pansartaxen
Posts: 4
Joined: Tue Aug 10, 2010 2:44 am

Problem getting \titlespacing and \baselineskip work togethe

Post by pansartaxen »

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:

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}
Nicer ideas are always welcome but I think this is kind of neat :)
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Problem getting \titlespacing and \baselineskip work togethe

Post by localghost »

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
Post Reply