I am in the process of writing my dissertation, and I need to fix widows and orphans in my table of contents.
For my dissertation, I also need to meet other strict formatting requirements, which I have already included in the below example. (I was given a template and I tried to modify it.)
Here is an illustration: in the below example, Section 4.1 is on a line by itself; Both Chapter 4 and Section 4.1 have to be moved to the subsequent page so that Section 4.1 is together with Section 4.2 (and Section 4.3) to avoid widow/orphan problems.
How do I modify the example to do this for sections and subsections, and appendices?
Also how do I modify the list of tables and list of figures similarly?
This is fairly urgent so I need help soon from a LaTeX guru. Let me know if I can be of assistance in illustrating what I mean further.
(Also I have provided a screenshot illustrating the problem.)
Code: Select all
\documentclass[12pt,letterpaper]{report}
\usepackage[document]{ragged2e}
\usepackage[none]{hyphenat}
\usepackage{times}
\usepackage{ifthen}
\usepackage{calc}
\usepackage{fancyhdr}
\usepackage{setspace}
\usepackage[indentafter,newlinetospace]{titlesec}
\usepackage[dotinlabels]{titletoc}
\usepackage{ccaption}
\usepackage{lipsum} % not for use in the actual document
\renewcommand{\contentsname}{TABLE OF CONTENTS}
\renewcommand{\listtablename}{LIST OF TABLES}
\renewcommand{\listfigurename}{LIST OF FIGURES}
\renewcommand{\bibname}{REFERENCES}
%% Margins
\setlength{\textheight}{9in}
\setlength{\topmargin}{-0.5in}
\setlength{\headheight}{16pt}
\setlength{\headsep}{0.5in-\headheight}
\setlength{\textwidth}{5.8in}
\setlength{\parindent}{0.5in}
\newcommand{\relaxedspacing}{\doublespacing}
\doublespacing
\raggedbottom
\clubpenalty =10000
\widowpenalty =10000
\brokenpenalty=10000
\doublehyphendemerits=40000
\finalhyphendemerits =10000
\righthyphenmin=3
\lefthyphenmin=4
\renewcommand{\topfraction}{0.5}
\setlength{\emergencystretch}{2em}
\titleformat{\chapter}[display]{\normalsize\bfseries\filcenter}{Chapter~\thechapter}{0in}{}
\titlespacing{\chapter}{0pt}{-.4in}{.25in}
\titleformat{\section}[hang]{\normalsize\bfseries\raggedright}{\thesection\hspace{0.1in}}{0in}{}
\titlespacing{\section}{0pt}{.23in}{.13in}
\titleformat{\subsection}[hang]{\normalsize\bfseries\raggedright}{\thesubsection\hspace{0.1in}}{0in}{}
\titlespacing{\subsection}{0pt}{.2in}{.09in}
% MAKE SURE TEXT IN THE TOC DOES NOT EXCEED
% ABOUT 5 DOTS:
\contentsmargin[3em]{0in}
% This doesn't always work, keep reading.
\titlecontents{chapter}[0in]
{ \ifthenelse{\equal{\thecontentslabel}{1}}{
\vspace{1.3\baselineskip}Chapter\\ \normalsize
}{
\normalsize\vspace{.2\baselineskip}\raggedright
}
}
{\contentspush{\thecontentslabel.~}}
{}
{\titlerule*[.3em]{.}\thecontentspage}
{}
\titlecontents{section}[.3in]{}
{\contentspush{\thecontentslabel.~}}{}
{\titlerule*[.3em]{.}\thecontentspage}{}
\titlecontents{subsection}[.6in]{}
{\contentspush{\thecontentslabel.~}}{}
{\titlerule*[.3em]{.}\thecontentspage}{}
\titlecontents{subsubsection}[.9in]{}
{\contentspush{\thecontentslabel.~}}{}
{\titlerule*[.3em]{.}\thecontentspage}{}
\titlecontents{paragraph}[1.2in]{}
{\contentspush{\thecontentslabel.~}}{}
{\titlerule*[.3em]{.}\thecontentspage}{}
\titlecontents{subparagraph}[1.5in]{}
{\contentspush{\thecontentslabel.~}}{}
{\titlerule*[.3em]{.}\thecontentspage}{}
\titlecontents{table}[0in]{}
{\contentspush{Table~\thecontentslabel.~}}{}
{\titlerule*[.3em]{.}\thecontentspage}{}
\titlecontents{figure}[0in]{}
{\contentspush{Figure~\thecontentslabel.~}}{}
{\titlerule*[.3em]{.}\thecontentspage}{}
\setcounter{secnumdepth}{10}
\setcounter{tocdepth}{10}
\newlength{\contentslength}
\let\Oldlistoffigures\listoffigures
\renewcommand{\listoffigures}{
\cleardoublepage
% \phantomsection
\addcontentsline{toc}{chapter}{\listfigurename}
{\relaxedspacing \Oldlistoffigures }
}
\let\Oldlistoftables\listoftables
\renewcommand{\listoftables}{
\cleardoublepage
% \phantomsection
\addcontentsline{toc}{chapter}{\listtablename}
{\relaxedspacing \Oldlistoftables }
}
\let\Oldtableofcontents\tableofcontents
\renewcommand{\tableofcontents}{
\cleardoublepage
% \phantomsection
% \pdfbookmark[0]{\contentsname}{my_toc}
{\relaxedspacing \Oldtableofcontents}
\setcounter{tocdepth}{10}
}
\renewcommand{\appendixname}{Appendix}
\let\oldAppendix\appendix
\renewcommand{\appendix}{
\oldAppendix
\cleardoublepage
% \phantomsection
% \pdfbookmark[0]{APPENDICES}{my_apps}
\addtocontents{toc}{\protect \setcounter{tocdepth}{0} \par}
\titleformat{\chapter}[display]{\normalsize\bfseries\filcenter}{\appendixname~\thechapter}{0in}{}
\titlespacing{\chapter}{0pt}{-.4in}{.25in}
\titlecontents{chapter}[0in]{\setlength{\emergencystretch}{4.5em}\normalsize\vspace{.2\baselineskip}}
{\contentspush{Appendix~\thecontentslabel.~}}{}
{\titlerule*[.3em]{.}\thecontentspage}{}
}
\makeatletter
\def\@chapter[#1]#2{\ifnum \c@secnumdepth >\m@ne
\if@mainmatter
\refstepcounter{chapter}%
\typeout{\@chapapp\space\thechapter.}%
\addcontentsline{toc}{chapter}%
{\protect\numberline{\thechapter}#1}%
\else
\addcontentsline{toc}{chapter}{#1}%
\fi
\else
\addcontentsline{toc}{chapter}{#1}%
\fi
\chaptermark{#1}%
% \addtocontents{lof}{\protect\addvspace{10\p@}}% NEW
% \addtocontents{lot}{\protect\addvspace{10\p@}}% NEW
\if@twocolumn
\@topnewpage[\@makechapterhead{#2}]%
\else
\@makechapterhead{#2}%
\@afterheading
\fi}
\makeatother
% FINALLY HERE WE ARE.
\begin{document}
\raggedright
\pagenumbering{roman}
\tableofcontents % Looks great except for the Appendix
% Because I added ``Table" and ``Figure" I have to redefine the
% emergency stretch
\setlength{\emergencystretch}{3.5em}
% before I add the \listoftables and \listoffigures
\listoftables
\listoffigures
% Now I can go back to what I had before.
\setlength{\emergencystretch}{2em}
\clearpage
\pagenumbering{arabic}
\setlength{\parindent}{0.5in}
\chapter{HERE IS A CHAPTER}
\section{First section first section first section}
Stuff
\section{Second section second section second section}
Stuff
\section{Third section third section third section}
\subsection{First subsection first subsection first subsection}
Stuff
\subsection{Second subsection second subsection second subsection}
Stuff
\chapter{SECOND CHAPTER}
\section{First section first section first section}
Stuff
\section{Second section second section second section}
Stuff
\section{Third section third section third section}
\subsection{First subsection first subsection first subsection}
Stuff
\subsection{Second subsection second subsection second subsection}
Stuff
\chapter{THIRD CHAPTER}
\section{First section first section first section}
Stuff
\section{I decided to have a table}
\begin{table}[h]
\centering
\begin{tabular}{l}
My table content \\
More stuff
\end{tabular}
\caption{\label{myfirsttable}My first table}
\end{table}
\section{Third section third section third section}
\subsection{First subsection first subsection first subsection}
Stuff
\subsection{Second subsection second subsection second subsection}
Stuff
\chapter{FOURTH CHAPTER}
\section{First section first section first section}
Stuff
\section{Second section second section second section}
Stuff
\section{Third section third section third section}
\subsection{First subsection first subsection first subsection}
Stuff
\subsection{This subsection has a table}
Stuff
\begin{table}[h]
\centering
\begin{tabular}{l}
My table content \\
More stuff
\end{tabular}
\caption{\label{mysecondtable}My second table}
\end{table}
\appendix{An appendix}
Stuff
%\stepcounter{chapter}
%\addtocontents{toc}{\protect\LTXcontentsline {chapter}{{Appendix \thechapter}. TITLE FOR A SPECIAL APPENDIX}{TEXT} }
\end{document}