1

I want all my section headings and body text to be spaced as per below rule. I use article class.

Space before: 0pt

Space after: 50–100% of text size

Line spread = 135% of text size

How can this be done?

EDIT: MWE

\documentclass[12pt, oneside, a4paper]{article}
\usepackage{titlesec}%                          Define titles and spacing
\usepackage{lipsum}
\usepackage{fontspec}%                          Font specification
\usepackage{sectsty}%                               Section font
\usepackage{xcolor}%                                For colored things
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%   Font Declaration
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\setmainfont{Futura Book.ttf}[
BoldFont = Futura Book Bold.ttf,
ItalicFont = Futura Book Italic BT.ttf,
BoldItalicFont = Futura Book Bold Italic.ttf]

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%   Section Color.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\sectionfont{\color{blue}}
\subsectionfont{\color{gray}}
\subsubsectionfont{\color{gray}}
\paragraphfont{\color{gray}}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%   Titlesec Customizations 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%    
\titlespacing{\section}{0pt}{0pt}{0pt}
\titlespacing{\subsection}{0pt}{0pt}{0pt}
\titlespacing{\subsubsection}{0pt}{0pt}{0pt}        

\begin{document}
\section{A Section}
\lipsum[1]
\subsection{Sub-Section}
\lipsum[2]
\end{document}

I was wondering, why do you need MWE? But while creating this MWE I realized there is something not agreeable between titlesec and sectsty. If I comment out the section color instructions in preamble, titlesec comes into effect.

Thank you Arne for suggesting MWE.

I need coloured section headings AND the tight spacing. Help?

abyshukla
  • 411

1 Answers1

1

I changed my answer, to this code:

\documentclass{article}
\usepackage{ipsum}
\linespread{1.35}
\usepackage{titlesec}
\usepackage{xcolor}%                                For colored things
\usepackage{fontspec}%                          Font specification



\titleformat{\section}%
{\normalfont\Large\color{blue}}% format applied to label+text
{\parbox{1.1cm}{\thesection}}% label
{5pt}
{}


\titleformat{\subsection}%
{\normalfont\Large\color{gray}}% format applied to label+text
{\parbox{1.1cm}{\thesubsection}}% label
{5pt}
{}

\titlespacing\section{0pt}{-5pt plus 4pt minus 2pt}{0pt plus 2pt minus 20pt} %the -5pt is space before, experiment with the numbers
\titlespacing\subsection{0pt}{12pt plus 4pt minus 2pt}{0pt plus 2pt minus 2pt}
\titlespacing\subsubsection{0pt}{12pt plus 4pt minus 2pt}{0pt plus 2pt minus 2pt}

\begin{document}
\section{Section}
\lipsum[1]
\section{Section}
\subsection{test}
\lipsum[2]
\end{document}

Resulting in : enter image description here

Futura font is not working with me. Hope I fits your needs

  • Sorry for sounding so thick...I tried to set all the values to 0pt in \titlespacing\section{0pt}{12pt plus 4pt minus 2pt}{0pt plus 2pt minus 20pt} without any difference in spacing. Is there something I am doing incorrectly? I tried the negative values as well, without any luck...

    The only way I can have the spacing to conform to the above values is by commenting out the section color in MWE.

    – abyshukla Jan 27 '16 at 08:25
  • No probs. Did you tried \titlespacing\section{0pt}{50pt plus 4pt minus 2pt}{0pt plus 2pt minus 20pt} %the 12pt is space before, experiment with the numbers. I've justed tried it here: https://www.overleaf.com/4178760rmvfzv – Arne Timperman Jan 27 '16 at 08:47
  • Even \usepackage[compact]{titlesec} works like a charm IF I comment out \usepackage{sectsty}. But I lose the section colors. – abyshukla Jan 27 '16 at 08:50
  • in Overleaf, the futura font is giving me problems. (I'm not on "my" computer now, so I can't really test it on an offline system.)... I will try again in 4h ok? – Arne Timperman Jan 27 '16 at 09:00
  • I have placed a sample on overleaf here: https://www.overleaf.com/4178760rmvfzv#/12317408/ – abyshukla Jan 27 '16 at 09:04
  • Accepted this as a solution. Readers be aware that sectsty really messes up titlesec specifications. True story. – abyshukla Jan 29 '16 at 03:47