3

Using \part with titlesec introduces unwanted vertical space when \part is used in the document. Where is this space coming from?

\documentclass[letterpaper,12pt]{article}
\usepackage[showframe,margin=1in,includehead,paper=letterpaper,headsep=0em,headheight=0em,footskip=0in]{geometry}

\newcommand{\mytitle}[1]{\begin{center} \bf \LARGE {#1} \end{center}}

\usepackage[explicit]{titlesec}
\titleformat{\part}{\bf\Large\filcenter}{}{0em}{Part \thepart. \quad #1}
\titlespacing*{\part}{0em}{0em}{0em}
\titleformat{name=\part,numberless}{\bf}{}{0em}{\Large #1}

\titleformat{\section}{\bf\Large\filcenter}{}{0em}{Section \thesection. \quad #1}
\titlespacing*{\section}{0em}{0em}{0em}


\begin{document}
\mytitle{Hits the top }
\part{Test}

\newpage


\part{Does not hit the top}

\newpage
\section{Hits the Top}

\end{document}

1 Answer 1

1

I know part is the only heading that is not defined using the latex kernel's \@startsection in the article class i.e. it is completely isolated from section etc. This might have something to do with it. I am not sure what the problem is yet, but if you need a quick fix, you could redefine the article class part this way:

Output

enter image description here

  • remove the \par\nobreak after Part I:
  • Add period (.) after Part
  • added quad after .
  • Comment out \huge so that Part I is the same size as the heading itself
  • added \centering to center the heading

Redefinition

\documentclass[letterpaper,12pt]{article}
\usepackage[showframe,margin=1in,includehead,paper=letterpaper,headsep=0em,headheight=0em,footskip=0in]{geometry}

\newcommand{\mytitle}[1]{\begin{center} \bf \LARGE {#1} \end{center}}

\usepackage[explicit]{titlesec}
%\titleformat{\part}{\bf\Large\filcenter}{}{0em}{Part \thepart. \quad #1}
%\titlespacing*{\part}{0em}{0em}{0em}
%\titleformat{name=\part,numberless}{\bf}{}{0em}{\Large #1}

\titleformat{\section}{\bf\Large\filcenter}{}{0em}{Section \thesection. \quad #1}
\titlespacing*{\section}{0em}{0em}{0em}
    % Redefine Article Class Part (overwrites original article class definition)
\makeatletter
\def\part{%
   \if@noskipsec \leavevmode \fi
   \par
   \addvspace{4ex}%
   \@afterindentfalse
   \secdef\@part\@spart}
\def\@part[#1]#2{% Non-starred version
    \ifnum \c@secnumdepth >\m@ne
      \refstepcounter{part}%
      \addcontentsline{toc}{part}{\thepart\hspace{1em}#1}%
    \else
      \addcontentsline{toc}{part}{#1}%
    \fi
    {\parindent \z@ \raggedright
     \interlinepenalty \@M
     \normalfont
     \ifnum \c@secnumdepth >\m@ne
       \Large\bfseries \partname\nobreakspace\thepart.\quad%
%       \par\nobreak
     \fi
%     \huge 
     \bfseries\centering #2 %
     \markboth{}{}\par}%
    \nobreak
    \vskip 3ex
    \@afterheading}
\def\@spart#1{% Starred version
    {\parindent \z@ \raggedright
     \interlinepenalty \@M
     \normalfont
     %\huge 
     \bfseries \centering #1\par}%
     \nobreak
     \vskip 3ex
     \@afterheading}
\makeatother
\begin{document}
\mytitle{Hits the top }
\part{Test}

\newpage


\part{DOES hit the top}

\newpage
\section{Hits the Top}

\end{document}
2

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .