2

I am writing a cls-file for a conference template.

I like to control the padding before and after the section, subsection, subsubsection etc and I do this by the following definition:

\renewcommand{\section}{%
  \@startsection{section}{1}{0pt}{12pt}{3pt}{\normalsize\bfseries}}%

\renewcommand{\subsection}{%
  \@startsection{subsection}{2}{0pt}{12pt}{3pt}{\normalsize\bfseries}}%

\renewcommand{\subsubsection}{%
  \@startsection{subsubsection}{3}{0pt}{12pt}{3pt}{\normalsize\itshape}}%

This works fine untill I try to change from indented paragraphs to unindented parapgrah with a base line skip inbetween the paragraphs using the following:

\RequirePackage{parskip}
\setlength{\parindent}{0pt}
\setlength{\parskip}{\baselineskip}

But that causes extra unintended padding for my sections.

Any ideas of how to only effect text paragraphs with the parskip?

MWE code

paper.tex

\documentclass{mwe}
\usepackage[utf8]{inputenc}

\title{A title}

\author{A name}

\begin{document}
\maketitle

\section{Level 1}
An important text.

Some more important text.

\subsection{Level 2}
An important text.

Some more important text.t.

\subsubsection{Level 3}
An important text.

Some more important text.

\end{document}

mwe.cls

\NeedsTeXFormat{LaTeX2e}
\ProvidesClass{mwe}[2017/03/03 MWE paper class]

\DeclareOption{10pt}{\OptionNotUsed}
\DeclareOption{12pt}{\OptionNotUsed}
\DeclareOption{twocolumn}{\OptionNotUsed}
\DeclareOption*{\PassOptionsToClass{\CurrentOption}{article}}

\ProcessOptions\relax

\LoadClass[11pt,a4paper]{article}

\RequirePackage{parskip}

\renewcommand{\section}{%
  \@startsection{section}{1}{0pt}{12pt}{3pt}{\normalsize\bfseries}}%

\renewcommand{\subsection}{%
  \@startsection{subsection}{2}{0pt}{12pt}{3pt}{\normalsize\bfseries}}%

\renewcommand{\subsubsection}{%
  \@startsection{subsubsection}{3}{0pt}{12pt}{3pt}{\normalsize\itshape}}%

\setlength{\parindent}{0pt}
\setlength{\parskip}{\baselineskip}

\AtBeginDocument{%
  \pagestyle{plain}
}

\endinput
  • 1
    Welcome to TeX.SX! I recommend you to have a look at KOMA-Script and its options (or if you are forced to use "standard" classes: titlesec). But it would be really nice, if you could post a MWE. – TeXnician Mar 3 '17 at 8:22
  • 2
    Normally the answer would be to simply reduce the spacing in the section declarations by the 15pt you are adding from parskip, but you can't go negative without changing the indent flag (unless you use a modified startsection0 but you can go down to 0pt (or 1sp) do you really want the spacing around headings to be tighter than the inter paragraph space? – David Carlisle Mar 3 '17 at 9:43
  • @TeXnician - MWE added. – sehlstrom Mar 3 '17 at 15:35
  • I would recommend to not make the spacing around headings tighter than the inter paragraph space, because this would make the paragraphs become a stronger subdivision that the headings. BTW: I you use package parskip you do not need to change \parskip and \parindent yourself. – Schweinebacke Mar 3 '17 at 16:38
  • @Schweinebacke I agree. However, I have not setup the rules regarding the spacing between parts this conference template uses. – sehlstrom Mar 5 '17 at 19:20
1

I don't think, that the space before a heading should be less than \parskip, so the following does not reduce spaces before headings that are less than \parskip. Nevertheless, it eliminates \parskip after headings:

\RequirePackage{filecontents}
\begin{filecontents*}{mwe.cls}
\NeedsTeXFormat{LaTeX2e}
\ProvidesClass{mwe}[2017/03/03 MWE paper class]

\DeclareOption{10pt}{\OptionNotUsed}
\DeclareOption{12pt}{\OptionNotUsed}
\DeclareOption{twocolumn}{\OptionNotUsed}
\DeclareOption*{\PassOptionsToClass{\CurrentOption}{article}}

\ProcessOptions\relax

\LoadClass[11pt,a4paper]{article}

\RequirePackage{parskip}
\setlength{\parskip}{\baselineskip}% Change parskip's default

% Eliminate \parskip after section headings
\RequirePackage{xpatch}
\xpatchcmd{\@xsect}{\vskip \@tempskipa}{\vskip
  \dimexpr\@tempskipa-\parskip\relax}{}{}
% Set only vertical spaces > \parskip before section headings
\xpatchcmd{\@startsection}{\addvspace\@tempskipa}{%
  \ifdim \@tempskipa>\parskip
    \addvspace{\dimexpr \@tempskipa-\parskip}%
  \fi
}{}{}

\renewcommand{\section}{%
  \@startsection{section}{1}{0pt}{12pt}{3pt}{\normalsize\bfseries}}%

\renewcommand{\subsection}{%
  \@startsection{subsection}{2}{0pt}{12pt}{3pt}{\normalsize\bfseries}}%

\renewcommand{\subsubsection}{%
  \@startsection{subsubsection}{3}{0pt}{12pt}{3pt}{\normalsize\itshape}}%

\AtBeginDocument{%
  \pagestyle{plain}
}

\endinput
\end{filecontents*}
\documentclass{mwe}
\usepackage[utf8]{inputenc}

\title{A title}

\author{A name}

\begin{document}
\maketitle

\section{Level 1}
An important text.

Some more important text.

\subsection{Level 2}
An important text.

Some more important text.t.

\subsubsection{Level 3}
An important text.

Some more important text.

\end{document}

ugly headings

Caveat: I would never use such a layout. It's ugly and breaks the significance of headings.

  • Thanks! It did the trick, but as you point out it looks ugly :( – sehlstrom Mar 6 '17 at 8:39

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.