1

I am stuck with a very strict requirement to keep the space between chapter/sections/subsections/paragraph headers the same. After a chapter header, I need to have a triple space. After section headers, I need to have a double space. I have been able to do this, however, if I do not have additional text between a chapter title and the first section header, then the spaces add (triple space + double space). Is there a way to have an if statement acknowledges that if there is text, only use a triple space, whereas if the text is displayed, then use the double space?

\titlespacing{\chapter}{0in}{\UOneInChapterSpace}{\UHeadSpace}[0in] 
\titlespacing{\section}{0in}{0in}{\UDoubleSpace}[0in]
\titlespacing{\subsection}{0in}{0in}{\UDoubleSpace}[0in]
\titlespacing{\subsubsection}{0in}{0in}{\UDoubleSpace}[0in]
\titlespacing{\paragraph}{1em}{1ex}{1ex}[1em]

\titleformat{\chapter}
    [display]
    {\color{URED}\centering\normalfont\Large\bfseries\doublespacing}
    {\MakeUppercase{\chaptertitlename} \Large\thechapter}
    {0in}
    {\MakeUppercase}
    []

\titleformat{\section}
    [hang]
    {\centering\singlespacing\normalfont\Large\bfseries}
    {\thesection}
    {1ex}
    {}
    []

\titleformat{\subsection}
    [hang]
    {\centering\singlespacing\normalfont\large\bfseries}
    {\thesubsection}
    {1ex}
    {}
    []

\titleformat{\subsubsection}
    [hang]
    {\centering\singlespacing\normalfont\normalsize\bfseries}
    {\thesubsubsection}
    {1ex}
    {}
    []

\titleformat{\paragraph}
    [runin]
    {\centering\singlespacing\normalfont\normalsize\bfseries}
    {\theparagraph}
    {1ex}
    {}
    []

\titleformat{\subparagraph}
    [runin]
    {\centering\singlespacing\normalfont\normalsize\bfseries}
    {\thesubparagraph}
    {1ex}
    {}
    []

I posted a previous question that has the entire cls file (Link). I'm just not sure how to do this.

Thank you!

9
  • Pleas see my answer to your previous question tex.stackexchange.com/a/597520/161015 May 17 at 23:46
  • Are you using \documentclass{MastersDoctoralThesis} ? May 18 at 13:24
  • Yes, I am using the class file mentioned in the link. I was the one who wrote it but was just not sure how to address this spacing issue. May 18 at 18:31
  • Ohh! I was preparing an answer for the preamble. Now I will see how to modify the class. May 18 at 19:18
  • 1
    Did my answer to your former question helped? It was a nice challenge to find where the extra space was coming from. May 18 at 19:24
1

You might incorporate these setting to your class. The grid is set to \baselineskip at doublespace. No extra space appears after title and section if there is no text.

%%***************************************************** titlespacing starts
\newlength{\Beforesec}
\setlength{\Beforesec}{2ex}
\newlength{\Aftersec}
\setlength{\Aftersec}{1ex}

\setlength{\UOneInChapterSpace}{-45pt + 1in} 
\setlength{\UHeadSpace}{3\baselineskip}
\setlength{\UDoubleSpace}{2\baselineskip}   

\titlespacing{\chapter}{0in}{\UOneInChapterSpace}{\UHeadSpace+\Beforesec}[0in] 
\titlespacing{\section}{0in}{\Beforesec}{\UDoubleSpace+\Aftersec}[0in]
\titlespacing{\subsection}{0in}{0in}{0.5\UDoubleSpace}[0in]
\titlespacing{\subsubsection}{0in}{0in}{0.5\UDoubleSpace}[0in]
\titlespacing{\paragraph}{1em}{1ex}{1ex}[1em]
%%***************************************************** titlespacing ends

Section after title without text in between

w

Text after title

z

Test this code

% !TeX TS-program = pdflatex

\documentclass{MastersDoctoralThesis}

\usepackage{eso-pic}
\AddToShipoutPictureBG{% GRID
    \begin{tikzpicture}[remember picture, overlay,
        help lines/.append style={line width=0.05pt,
            color=white},
        major divisions/.style={help lines,line width=0.5pt,
            color=blue!40} ]
        \draw[help lines] (current page.south west) grid[step=0.5pt]
        (current page.north east);
        \draw[major divisions] (current page.south west) grid[step=22pt] % baselineskip = 22pt at double space
        (current page.north east);
    \end{tikzpicture}%
}   

%%***************************************************** titlespacing starts
\newlength{\Beforesec}
\setlength{\Beforesec}{2ex}
\newlength{\Aftersec}
\setlength{\Aftersec}{1ex}

\setlength{\UOneInChapterSpace}{-45pt + 1in} 
\setlength{\UHeadSpace}{3\baselineskip}
\setlength{\UDoubleSpace}{2\baselineskip}   

\titlespacing{\chapter}{0in}{\UOneInChapterSpace}{\UHeadSpace+\Beforesec}[0in] 
\titlespacing{\section}{0in}{\Beforesec}{\UDoubleSpace+\Aftersec}[0in]
\titlespacing{\subsection}{0in}{0in}{0.5\UDoubleSpace}[0in]
\titlespacing{\subsubsection}{0in}{0in}{0.5\UDoubleSpace}[0in]
\titlespacing{\paragraph}{1em}{1ex}{1ex}[1em]
%%***************************************************** titlespacing ends

\begin{document}
\mainMatter %% sets\doublespacing 

\chapter[\uppercase{Multiline title}]{\uppercase{Multiline \protect \\  title}} 
1   \lipsum[1]
\section{Section1}
2   \lipsum[2]
\section{Section2}
\section{Section3}
\section{Section4}
3   \lipsum[3]
\subsection{Subsection1}
4   \lipsum[4]  
\subsection{Subsection2}    
\subsection{Subsection3}    
\subsection{Subsection4}
5   \lipsum[5]  
\paragraph{Paragraph1}
6   \lipsum[6]  
\paragraph{Paragraph2}
\paragraph{Paragraph3}
\paragraph{Paragraph4}
7   \lipsum[7]
\end{document
2
  • That is so close. However, I'm still getting slightly more space between a chapter title and no text before a section header than a chapter title with text before the section header. Using SumatraPDF it appears that there is an additional 0.9 in space before the section header when I set all spaces to 0\baselineskip. Would you by chance know how to fix that? May 20 at 23:39
  • @Christopher Creveling LaTeX does not typeset on a grid. There are al lot of glue space in that page to make nice paragraphs instead. See tex.stackexchange.com/a/405237/161015 May 21 at 12:43

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.