[Tex/LaTex] Headings run into the right margin

marginssectioning

I am using TexMaker to prepare my PhD dissertation and this is actually my first real experience with LaTeX!

I am using titlesec to customize my headings. However, for some reason, some of the headings run into the right margin. Could you please help me fix the problem?!

I have attached a simple example.

\documentclass[12pt]{report}

\usepackage[letterpaper]{geometry}
\geometry{verbose,tmargin=1.25in,bmargin=1.25in,lmargin=1.4in,rmargin=1.15in}
\pagestyle{plain}
\usepackage[doublespacing]{setspace}

\usepackage{titletoc}
\usepackage{titlesec}
\setcounter{secnumdepth}{3}
\setcounter{tocdepth}{3}
\titleformat{\chapter}{\normalfont\Large\bfseries\fillast\singlespacing}{\thechapter}{1em}{}
\titleformat{\section}{\normalfont\large\bfseries\singlespacing}{\thesection}{1em}{}
\titleformat{\subsection}{\normalfont\bfseries\singlespacing}{\thesubsection}{1em}{}

\begin{document}

\chapter{\MakeUppercase{Overview of the Notional All-Electric Ship Model}}

Text goes here.Text goes here.Text goes here.Text goes here.
Text goes here.Text goes here.Text goes here.Text goes here.
Text goes here.Text goes here.Text goes here.Text goes here.
Text goes here.

\end{document}

Best Answer

Hyphenated words do not automatically hyphenate, and generally it is often a good idea with titles to line break by hand. However you don't want the uppercasing or line breaks in the table of contents or page head so move the uppercase to the format, and use the optional argument to supply a second version for the toc.

\documentclass[12pt]{report}

\usepackage[letterpaper]{geometry}
\geometry{verbose,tmargin=1.25in,bmargin=1.25in,lmargin=1.4in,rmargin=1.15in}
\pagestyle{plain}
\usepackage[doublespacing]{setspace}

\usepackage{titletoc}
\usepackage{titlesec}
\setcounter{secnumdepth}{3}
\setcounter{tocdepth}{3}
\titleformat{\chapter}{\normalfont\Large\bfseries\fillast\MakeUppercase}{\thechapter}{1em}{}
\titleformat{\section}{\normalfont\large\bfseries\singlespacing}{\thesection}{1em}{}
\titleformat{\subsection}{\normalfont\bfseries\singlespacing}{\thesubsection}{1em}{}

\begin{document}

\chapter[Overview of the Notional All-Electric Ship Model]
          {Overview of the Notional\protect\\ All-Electric Ship Model}

Text goes here.Text goes here.Text goes here.Text goes here.
Text goes here.Text goes here.Text goes here.Text goes here.
Text goes here.Text goes here.Text goes here.Text goes here.
Text goes here.

\end{document}