我注意到,在我的文档类中,当章节标题很长时,标题可能会与页面上的第一行文本混在一起。我的默认间距是 50pt。如果我将其设置得更高,比如 150pt,那么带有长章节名称的页面看起来不错,但其余所有带有单行章节名称的页面下方都有太多空白,不符合我的口味。
我不想手动更改每个章节的间距...有没有办法将间距与用于章节标题的小页面的大小联系起来?
\documentclass{book}
\let\cleardoublepage\clearpage
\RequirePackage{tikz}
\RequirePackage[explicit]{titlesec}
\RequirePackage{DejaVuSansCondensed}
\RequirePackage[normalem]{ulem}
\RequirePackage[
left=2.25in,
right=0.75in,
top=1.25in,
bottom=1.25in,
marginparwidth=1.75in,
marginparsep=.25in,
asymmetric]{geometry}
\renewcommand*\familydefault{\sfdefault} % Set default font
\makeatletter
\titleformat{\chapter}
{\normalfont\sffamily\Huge\scshape}
{}{0pt}
{\thispagestyle{empty} % Remove page number on new chapters
%\setcounter{definition}{0}
\begin{tikzpicture}[remember picture,overlay]
\node[yshift=-3cm] at (current page.north west)
{\begin{tikzpicture}[remember picture, overlay]
\draw[fill=cyan] (0,-1) rectangle
(25cm,3cm);
\draw[fill=cyan] (0,-24) rectangle
(25cm,-25cm);
\ifttl@label% <---------------------- Added condition on \ifttl@label
\node[anchor=west,xshift=.21\paperwidth,yshift=-.01\paperheight,rectangle]
{\color{white}\LARGE \MakeUppercase{\@chapapp} \Huge\thechapter};
\fi% <------------------------------- end condition on \ifttl@label
\node[anchor=north west,xshift=.21\paperwidth,yshift=-.040\paperheight,rectangle]
{\begin{minipage}{.9\textwidth}
\color{cyan}\Huge\raggedright\MakeUppercase{#1}
\end{minipage}};
\end{tikzpicture}
};
\end{tikzpicture}
}
\makeatother
\titlespacing*{\chapter}{0pt}{50pt}{0pt}{}
\titleformat{\section}{\color{cyan}\itshape\LARGE}{\llap{\thesection} #1}{1em}{}[\titleline{\color{cyan}\titlerule[1pt]}]
\titleformat{\subsection}{\color{cyan}\normalfont\large}{\; #1}{1em}{}
\begin{document}
\chapter{A normal chapter}
\section{A Section}
\chapter{ON COMPUTABLE NUMBERS, WITH AN APPLICATION TO THE ENTSCHEIDUNGSPROBLEM}
\section{Another Section}
\end{document}
答案1
正常情况下 latex 会留出空间,但固定高度的框阻止了这一点。您可以将章节文本从框中取出,让其参与正常的页面流,然后以下章节标题将正常定位,如下所示:
\documentclass{book}
\let\cleardoublepage\clearpage
\RequirePackage{tikz}
\RequirePackage[explicit]{titlesec}
\RequirePackage{DejaVuSansCondensed}
\RequirePackage[normalem]{ulem}
\RequirePackage[
left=2.25in,
right=0.75in,
top=1.25in,
bottom=1.25in,
marginparwidth=1.75in,
marginparsep=.25in,
asymmetric]{geometry}
\renewcommand*\familydefault{\sfdefault} % Set default font
\makeatletter
\titleformat{\chapter}
{\normalfont\sffamily\Huge\scshape}
{}{0pt}
{\thispagestyle{empty} % Remove page number on new chapters
%\setcounter{definition}{0}
\begin{tikzpicture}[remember picture,overlay]
\node[yshift=-3cm] at (current page.north west)
{\begin{tikzpicture}[remember picture, overlay]
\draw[fill=cyan] (0,-1) rectangle
(25cm,3cm);
\draw[fill=cyan] (0,-24) rectangle
(25cm,-25cm);
\ifttl@label% <---------------------- Added condition on \ifttl@label
\node[anchor=west,xshift=.21\paperwidth,yshift=-.01\paperheight,rectangle]
{\color{white}\LARGE \MakeUppercase{\@chapapp} \Huge\thechapter};
\fi% <------------------------------- end condition on \ifttl@label
\end{tikzpicture}
};
\end{tikzpicture}\endgraf
\vskip-.7cm
\color{cyan}\Huge\raggedright\leftskip-1cm
\noindent\MakeUppercase{#1}\endgraf
}
\makeatother
\titlespacing*{\chapter}{0pt}{10pt}{0pt}{}
\titleformat{\section}{\color{cyan}\itshape\LARGE}{\llap{\thesection} #1}{1em}{}[\titleline{\color{cyan}\titlerule[1pt]}]
\titleformat{\subsection}{\color{cyan}\normalfont\large}{\; #1}{1em}{}
\begin{document}
\chapter{A normal chapter}
\section{A Section}
\chapter{ON COMPUTABLE NUMBERS, WITH AN APPLICATION TO THE ENTSCHEIDUNGSPROBLEM}
\section{Another Section}
\end{document}