![为什么 section 命令仅在页面顶部之前导致较大的垂直空间?](https://linux22.com/image/319700/%E4%B8%BA%E4%BB%80%E4%B9%88%20section%20%E5%91%BD%E4%BB%A4%E4%BB%85%E5%9C%A8%E9%A1%B5%E9%9D%A2%E9%A1%B6%E9%83%A8%E4%B9%8B%E5%89%8D%E5%AF%BC%E8%87%B4%E8%BE%83%E5%A4%A7%E7%9A%84%E5%9E%82%E7%9B%B4%E7%A9%BA%E9%97%B4%EF%BC%9F.png)
%
\documentclass{book} %
%
\usepackage[fleqn]{amsmath} %
\usepackage{amsthm,amssymb} %
\usepackage[explicit]{titlesec} %
\usepackage{titletoc} %
\usepackage[english]{babel} %
\usepackage{txfonts} %
\usepackage{xcolor}
\usepackage{colortbl} %
\usepackage[format=plain,listformat=empty,labelsep=space,position=below,width=\linewidth,labelfont={normal},font={normal}]{caption} %
\usepackage[margin=6pt,justification=raggedright]{subcaption} %
\usepackage[verbose]{geometry} %
\usepackage[a4,frame,center]{crop}
\usepackage[most]{tcolorbox}
\usepackage{bookmark} %
%
\setlength{\unitlength}{1mm} %
%
\paperwidth=170mm
\paperheight=240mm
\setlength{\textwidth}{132mm}
\definecolor{ThemeColour}{rgb}{0.45,0.00,0.45} %
\definecolor{DarkGrey}{rgb}{0.92,0.92,0.92}
\definecolor{DarkRed}{rgb}{0.45,0.00,0.00} %
\definecolor{LightCream}{rgb}{1.00,1.00,0.90} %
\newcommand\Hrule{\noindent\color{ThemeColour}{\rule{\linewidth}{3pt}}} %
\newcommand\hseprule{\color{DarkRed}{\rule{\linewidth}{0.7pt}}} %
\titleformat{\chapter}[display]
{\color{ThemeColour}\bfseries\itshape\fontsize{30}{30}\selectfont} %
{\Hrule\vspace*{6pt}\\ {\color{black}\,\chaptername\hspace{8pt}\normalfont\fontsize{42}{45}\selectfont{\thechapter}}} %
{0pt}{\bfseries\normalfont\fontsize{15}{18}\selectfont{#1} \\ \vspace*{-9pt}\Hrule}[\vspace{18pt}] %
\titlespacing{\chapter}{0pt}{12pt}{6pt}[0pt] %
\renewcommand{\thechapter}{\arabic{chapter}} %
\newtcolorbox{sectionbox}[2][]{boxsep=4.2pt,boxrule=1.2pt,arc=3pt,outer arc=3.2pt,width=\linewidth,
coltitle=white,colbacktitle=ThemeColour,after=\hfill,colframe=black,colback=DarkGrey,title={#2},fonttitle=\bfseries,#1}
\titleformat{\section} %
{\normalfont\bfseries\itshape\fontsize{12}{14}\selectfont}
{}{0pt}
{\begin{sectionbox}
{\fontsize{14}{16}\selectfont{Section\hspace{5.6pt}\thetitle}}{#1}
\end{sectionbox}}
\titlespacing{\section}{0pt}{10pt}{6pt}[0pt] % 0, 10, 6, 0
\renewcommand{\thesection}{\arabic{section}} % make-up of number
%
\def\figtab{\kern 0.8pt}
\addto\captionsenglish{ % this seems to work
\renewcommand{\figurename}{Fig\hspace{0.7pt}.} %
\renewcommand{\thefigure}{\thechapter{\figtab.\figtab}\arabic{figure}} % good
\renewcommand{\thesubfigure}{\hspace{0.5pt}\alph{subfigure}\hspace{0.4pt}} %
}
\begin{document}
\pagestyle{plain}
\chapter{Introduction to number}
\section{Section one - only small gap above (ok)}
\section{Section two - directly follows section one - gap ok}
\section{Section three - directly follows section two}
\clearpage
\section{Section four - shows 40mm gap at the top of the page (far too much)}
\section{Section five - directly follows section four - gap ok}
\section{Section six} \vspace{50mm}
\noindent Even though the page is nearly full.\vspace{50mm}
\noindent Even though the page is nearly full.
\end{document}
答案1
你必须加载geometry
前 crop
,带有选项driver=none
。此外,我将您的尺寸规范作为选项合并到几何包中,并添加了选项showframe
和showcrop
,以显示实际发生的情况。
去除全部页面顶部的垂直间距,我nobeforeafter
在 中使用的 \tcolorbox 中添加了选项\titleformat{\section}
,因此间距完全由 管理\titlespacing{\section}
。
%
\documentclass[a4paper]{book} %
%
\usepackage[fleqn]{amsmath} %
\usepackage{amsthm,amssymb} %
\usepackage[explicit]{titlesec} %
\usepackage{titletoc} %
\usepackage[english]{babel} %
\usepackage{txfonts} %
\usepackage{xcolor}
\usepackage{colortbl} %
\usepackage[format=plain,listformat=empty,labelsep=space,position=below,width=\linewidth, labelfont={normal},font={normal}]{caption} %
\usepackage[margin=6pt,justification=raggedright]{subcaption} %
\usepackage[paperwidth=170mm, paperheight=240mm, textwidth=132mm,verbose, driver=none, showcrop, showframe]{geometry}
%
\usepackage[a4,frame,center]{crop}
\usepackage[most]{tcolorbox}
\usepackage{bookmark} % %
%
\setlength{\unitlength}{1mm} %
\definecolor{ThemeColour}{rgb}{0.45,0.00,0.45} %
\definecolor{DarkGrey}{rgb}{0.92,0.92,0.92}
\definecolor{DarkRed}{rgb}{0.45,0.00,0.00} %
\definecolor{LightCream}{rgb}{1.00,1.00,0.90} %
\newcommand\Hrule{\noindent\color{ThemeColour}{\rule{\linewidth}{3pt}}} %
\newcommand\hseprule{\color{DarkRed}{\rule{\linewidth}{0.7pt}}} %
\titleformat{\chapter}[display]
{\color{ThemeColour}\bfseries\itshape\fontsize{30}{30}\selectfont} %
{\Hrule\vspace*{6pt}\\ {\color{black}\,\chaptername\hspace{8pt}\normalfont\fontsize{42}{45}\selectfont{\thechapter}}} %
{0pt}{\bfseries\normalfont\fontsize{15}{18}\selectfont{#1} \\ \vspace*{-9pt}\Hrule}[\vspace{18pt}] %
\titlespacing{\chapter}{0pt}{12pt}{6pt}[0pt] %
\renewcommand{\thechapter}{\arabic{chapter}} %
\newtcolorbox{sectionbox}[2][]{nobeforeafter, boxsep=4.2pt,boxrule=1.2pt,arc=3pt,outer arc=3.2pt,width=\linewidth,
coltitle=white,colbacktitle=ThemeColour,after=\hfill,colframe=black,colback=DarkGrey,title={#2},fonttitle=\bfseries,#1}
\titleformat{\section} %
{\normalfont\bfseries\itshape\fontsize{12}{14}\selectfont}
{}{0pt}
{\begin{sectionbox}
{\fontsize{14}{16}\selectfont{Section\hspace{5.6pt}\thetitle}}{#1}
\end{sectionbox}}
\titlespacing{\section}{0pt}{10pt}{6pt}[0pt] % 0, 10, 6, 0
\renewcommand{\thesection}{\arabic{section}} % make-up of number
%
\def\figtab{\kern 0.8pt}
\addto\captionsenglish{ % this seems to work
\renewcommand{\figurename}{Fig\hspace{0.7pt}.} %
\renewcommand{\thefigure}{\thechapter{\figtab.\figtab}\arabic{figure}} % good
\renewcommand{\thesubfigure}{\hspace{0.5pt}\alph{subfigure}\hspace{0.4pt}} %
}
\raggedbottom
\begin{document}
\pagestyle{plain}
\chapter{Introduction to number}
\section{Section one - only small gap above (ok)}
\section{Section two - directly follows section one - gap ok}
\section{Section three - directly follows section two}
\clearpage
\section{Section four - shows 40mm gap at the top of the page (far too much)}
\section{Section five - directly follows section four - gap ok}
\section{Section six} \vspace{50mm}
\noindent Even though the page is nearly full.\vspace{50mm}
\noindent Even though the page is nearly full.
\end{document}