5

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}
2
  • Welcome to TeX.sx! A tip: If you indent lines by 4 spaces, they'll be marked as a code sample. You can also highlight the code and click the "code" button (with "{}" on it).
    – yo'
    Feb 21 '13 at 16:43
  • Just one suggestion. Have you considered using the title Notional All-Electric Ship Model Overview? It's shorter, so it could overcome the problem. Also it seems more to the point.
    – user10274
    Feb 21 '13 at 17:08
6

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}
1
  • Thank you so much David. I knew I could manually fix it, but I did not know what the problem was. So, the problem is that the word is hyphenated itself.
    – Salman
    Feb 21 '13 at 18:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.