I am trying to use latex to write my thesis, and I have modified a template to use, but am having trouble with some of my section headings. Specifically, with the weird spacing between words caused by the section heading being justified, rather than flush left.
I am using the titlesec package and have tried:
\titleformat{\section}{\raggedright\large\sffamily\bf}{\thesection}{1em}{}
I also tried forcing titlesec to make everything raggedright by adding
\usepackage[raggedright]{titlesec}
to my preamble but neither seem to have any effect and the heading text is still strangely spaced. I think it is probably something else within my settings that is taking preference?
\documentclass[11 pt]{report}
%-----------------------------------------
% Packages
%-----------------------------------------
\usepackage{titlesec}
\usepackage[a4paper, scale=1.0, textwidth=145mm, textheight=237mm, layoutvoffset=0pt, layouthoffset=0pt, ignoremp, includehead, marginparsep=0pt, bottom=4cm, top=2cm, left=4cm, right=2.5cm, verbose=true, bindingoffset=0pt]{geometry}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[english]{babel}
\usepackage{setspace}
\usepackage[toc, page, header]{appendix}
\usepackage{fancyhdr}
\usepackage[plain]{fancyref}
\usepackage{textcomp}
\usepackage{sectsty}
\usepackage{balance}
\usepackage{lastpage}
\usepackage[format=plain,justification=centering,singlelinecheck=false,font=small,labelfont=bf,labelsep=space]{caption}
%-----------------------------------------------------------------------
% MAIN PAGE SETUP
%-----------------------------------------------------------------------
\renewcommand{\rmdefault}{ptm} % sets roman font to Times ('ptm')
\renewcommand{\sfdefault}{phv} % sets serif font to Helvetica
\renewcommand{\ttdefault}{lmtt} % sets text type font to Latin Modern Typewriter ('ptm')
\widowpenalty=500
\clubpenalty=500
\pretolerance=10000
\tolerance=2000 %
\emergencystretch=10pt
\titleformat{\section}{\fillleft\large\sffamily\bf}{\thesection}{1em}{} %formats the section titles
\begin{document}
\onehalfspace
\chapter[Introduction]{Introduction}
\chaptermark{Introduction}
\label{ch:introduction} % label for referring to chapter in other parts of the thesis
\section[Importance]{Importance}\label{C1:Intro}
Filling in later
\section[Synthesis]{Synthesis of averylongcompoundnamethatis toobigtofitinthisbox}
blahblahblah
\end{document}
Best Answer
You are already loading package
sectsty
. Then useor do not load package secsty and
\titleformat
will also work. If you want to allow hyphenation then use: