# Section Headings With Long Titles

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{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}


-
Welcome to TeX.SX! Please help us to help you and add a minimal working example (MWE) that illustrates your problem. It will be much easier for us to reproduce your situation and find out what the issue is when we see compilable code, starting with \documentclass{...} and ending with \end{document}. Your document is so long, that is hard to tell where the error might be –  Christian Hupfer Jun 11 '14 at 6:38
Hi. Yeah I know, I think this is where I am having trouble as well. I will try and cut parts out and see if they have an effect. –  Dylan Jun 11 '14 at 6:45
I think, it is the \pretolerance Please turn it off by adding a % before! –  Christian Hupfer Jun 11 '14 at 6:47
Do you really want hyphenation turned off for the whole thesis? –  Andrew Swann Jun 11 '14 at 6:54
If you don't want hyphenation you should set the whole document raggedright, justifying paragraphs with no hyphenation will make a horrible result with over-stretched space –  David Carlisle Jun 11 '14 at 7:32

You are already loading package sectsty. Then use

\sectionfont{\raggedright\large\sffamily\bfseries}


or do not load package secsty and \titleformat will also work. If you want to allow hyphenation then use:

\usepackage{ragged2e}
\sectionfont{\RaggedRight\large\sffamily\bfseries}

-
Yes, this seems to do what I was asking, how come this works while the titlesec seemed to just ignore me? –  Dylan Jun 11 '14 at 7:11
Do not load package secsty and titlesecwill also work. –  Herbert Jun 11 '14 at 7:14

The \pretolerance value is too large, preventing a hyphenation and its consequent line break and therefore stretches the line to break at the next possible position, i.e. at toobig... The problem vanishes after turning it off (by commenting it)

\documentclass[11pt]{report}

\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{titlesec}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[english]{babel}
\usepackage{setspace}
\usepackage{fancyhdr}
\usepackage[super,sort&compress,comma]{natbib}
\usepackage[plain]{fancyref}
\usepackage[version=3]{mhchem}
\usepackage{times,mathptmx}
\usepackage{textcomp}
\usepackage{sectsty}
\usepackage{balance}
\usepackage{graphicx}
\usepackage{lastpage}
\usepackage[format=plain,justification=centering,singlelinecheck=false,font=small,labelfont=bf,labelsep=space]{caption}

\newcommand{\mk}[1]{%
%
}

%-----------------------------------------------------------------------
%   MAIN PAGE SETUP
%-----------------------------------------------------------------------

% This section is relevant to formatting within chapters
\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')
\pagestyle{fancyplain} % retains control of headers and footers
\fancyhf{}
\renewcommand{\headrulewidth}{0.4pt} % thickness of rule in header line (0pt will make it disappear)
\fancyfoot[R]{\thepage}
\renewcommand{\footrulewidth}{0.4pt} % thickness of rule in footer line

\parindent=12pt % Sets indentation for each paragraph
\parskip=0.1in % Sets vertical space before a new paragraph
\widowpenalty=500 % elliminates widows (single lines of a paragraph on the top of the next page), see line below
\clubpenalty=500 % these two lines eliminate widows and orphans from the document, but may affect typesetting quality elsewhere.

%\pretolerance=10000 % turns off hyphenation

\tolerance=2000 % turns off hyphenation
\emergencystretch=10pt % turns off hyphenation

%  The following changes the Chapter Title format

\titleformat{\section}{\raggedright\large\sffamily\bf}{\thesection}{1em}{} %formats the section titles

% for a bit more fancy chapter and section titles use the following 12 lines:
\renewcommand{\thechapter}{\arabic{chapter}}
\titleformat{\chapter}[display]
{\bfseries\Large}
{\filleft\MakeUppercase{\chaptertitlename} \Huge\thechapter}
{4ex}
{\titlerule
\vspace{2ex}%
\filright
}%
[\vspace{2ex}%
\titlerule]
\renewcommand{\captionfont}{\sffamily}{\small}
\renewcommand{\captionlabelfont}{\bf}

\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}

-
Yeah, but this then causes it to hyphenate halfway through the word - which I was trying to avoid. I would rather the line break between the words and have it all pushed to the left if possible? –  Dylan Jun 11 '14 at 6:55
You can use another value of \pretolerance at an appropiate place mid-document –  Christian Hupfer Jun 11 '14 at 6:56
Ok, but then what if I use another compound with a long name later on? –  Dylan Jun 11 '14 at 7:04
Is there a more appropriate value to use for the pretolerance? Or does latex generally handle these ok? Sometimes they can be placed strangely. –  Dylan Jun 11 '14 at 7:14
Honestly spoken: In nearly 20 years of TeXing I was never in need of changing \pretolerance, so LaTeX handles it in most cases correctly ;-) –  Christian Hupfer Jun 11 '14 at 7:17