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?

6
  • Have you looked here: tex.stackexchange.com/questions/53338/… Jan 21, 2016 at 15:14
  • Yes I have. Set all to 0pt. But it hasn't reduced the spacing.
    – abyshukla
    Jan 21, 2016 at 15:17
  • Maybe you can adapt your question with a MWE. So we can see what you have done/tried. Jan 21, 2016 at 15:29
  • Done. btw, how do I tag people here? The @ seems to have no effect.
    – abyshukla
    Jan 22, 2016 at 5:13
  • a MWE is very handy for two reasons. 1) possible errors can be found. 2) if you want to help, it is easier to start of a "working" file. It saves a lot of time. Jan 22, 2016 at 10:35

1 Answer 1

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

6
  • 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, 2016 at 8: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: overleaf.com/4178760rmvfzv Jan 27, 2016 at 8:47
  • Even \usepackage[compact]{titlesec} works like a charm IF I comment out \usepackage{sectsty}. But I lose the section colors.
    – abyshukla
    Jan 27, 2016 at 8: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? Jan 27, 2016 at 9:00
  • I have placed a sample on overleaf here: overleaf.com/4178760rmvfzv#/12317408
    – abyshukla
    Jan 27, 2016 at 9:04

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .