输出

输出

在文档中使用时,使用\partwithtitlesec会引入不必要的垂直空间。这个空间来自哪里?\part

\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

我知道 part 是文章类中唯一未使用 latex 内核定义的标题,\@startsection即它与部分等完全隔离。这可能与它有关。我还不确定问题是什么,但如果您需要快速修复,您可以这样重新定义文章类部分:

输出

在此处输入图片描述

  • 删除\par\nobreak第一部分之后的内容:
  • .在部分后添加句号( )
  • 之后添加了四边形。
  • 注释掉\huge,使第一部分与标题本身的大小相同
  • 添加\centering到标题中心

重新定义

\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}

相关内容