我在双列环境中使用 titlesec,有时我的部分从新页面或第二列开始,并在上一页/列的底部留下空白块。
我将文本环绕在章节编号周围,并将章节编号格式化为 2 行高。我想告诉 Latex,如果有足够的空间容纳两行高,则可以将章节的开头放在页面底部。
这是一个相关的例子。第二部分从第二列开始,我希望它从第一列的底部开始。
\documentclass[10pt,twocolumn,twoside,openany]{book}
\usepackage[margin=.5in, paperwidth=6in, paperheight=9in]{geometry}
\usepackage{titlesec}
\titleformat{\chapter}[block]{\fontfamily{phv}\Huge\filcenter\selectfont}{\thechapter}{0em}{\MakeUppercase}
\titlespacing{\chapter}{0pc}{0ex plus .1ex minus .1ex}{2pc}
\titleformat{\section}[wrap]{\fontfamily{ptm}\fontsize{24}{32}\selectfont}{\thesection.}{5pt}{\vskip-0.5em}
\titlespacing{\section}{6pt}{-2ex plus .1ex minus .1ex}{6pt}
\setcounter{secnumdepth}{0}
\setcounter{tocdepth}{1}
\renewcommand{\thechapter}{}
\renewcommand{\chaptername}{}
\renewcommand{\chaptermark}[1]{\markboth{#1}{}}
\begin{document}
\chapter{New Chapter}
\section{1} HERE IS SOME TEXT THAT DOESN'T TAKE UP THE WHOLE COLUMN.\newline
HERE IS SOME TEXT THAT DOESN'T TAKE UP THE WHOLE COLUMN.\newline
HERE IS SOME TEXT THAT DOESN'T TAKE UP THE WHOLE COLUMN.\newline
HERE IS SOME TEXT THAT DOESN'T TAKE UP THE WHOLE COLUMN.\newline
HERE IS SOME TEXT THAT DOESN'T TAKE UP THE WHOLE COLUMN.\newline
HERE IS SOME TEXT THAT DOESN'T TAKE UP THE WHOLE COLUMN.\newline
HERE IS SOME TEXT THAT DOESN'T TAKE UP THE WHOLE COLUMN.\newline
HERE IS SOME TEXT THAT DOESN'T TAKE UP THE WHOLE COLUMN.\newline
HERE IS SOME TEXT THAT DOESN'T TAKE UP THE WHOLE COLUMN.\newline
HERE IS SOME TEXT THAT DOESN'T TAKE UP THE WHOLE COLUMN.\newline
HERE IS SOME TEXT THAT DOESN'T TAKE UP THE WHOLE COLUMN.\newline
HERE IS SOME TEXT THAT DOESN'T TAKE UP THE WHOLE COLUMN.\newline
HERE IS SOME TEXT THAT DOESN'T TAKE UP THE WHOLE COLUMN.\newline
\section{2} HERE IS SOME MORE TEXT THAT SHOULD START AT THE\newline BOTTOM OF FIRST COLUMN.
HERE IS SOME MORE TEXT IN THE SECOND SECTION. THIS CAN WRAP TO SECOND COLUMN IF NECESSARY.\newline
HERE IS SOME MORE TEXT IN THE SECOND SECTION. THIS CAN WRAP TO SECOND COLUMN IF NECESSARY.\newline
HERE IS SOME MORE TEXT IN THE SECOND SECTION. THIS CAN WRAP TO SECOND COLUMN IF NECESSARY.\newline
HERE IS SOME MORE TEXT IN THE SECOND SECTION. THIS CAN WRAP TO SECOND COLUMN IF NECESSARY.\newline
\end{document}
答案1
节标题的间距决定了需要多少空间。如果要完全适合列,请减少间距。
您可以告诉 LaTeX 应保留多少空间。如果剩余空间不足,它会分别拆分页面或列。
needspace
package 是一个很好的工具。通过以下方式加载它\usepackage{needspace}
并在章节标题前写
\needspace{2\baselineskip}
或选择任何其他有意义的长度。该包提供了另一个命令,
\Needspace
该命令准确但效率较低。带星号的版本\Needspace*
以平齐底部而不是不规则底部的方式工作,这是默认行为。
答案2
经过大量的故障排除后,我发现我的间距问题是由我在该部分中使用的字体大小引起的:
\titleformat{\section}[wrap]{\fontfamily{ptm}\fontsize{24}{32}\selectfont}{\thesection.}{5pt}{\vskip-0.5em}
我发现当我把字体变小时我可以控制间距,如下例所示:
\titleformat{\section}[wrap]{\fontfamily{ptm}\small\selectfont}{\thesection.}{5pt}{\vskip-0.5em}
但是我需要更大的字体,当字体太大时,间距就成了问题。我尝试在我的部分中放置一个大字体,就像这样,这似乎有效,直到我开始在文档标题中显示部分编号。所以这是一个坏主意:
\section{\fontfamily{ptm}\fontsize{24}{32}\selectfont1} ... \section{\fontfamily{ptm}\fontsize{24}{32}\selectfont2} ... \section{\fontfamily{ptm}\fontsize{24}{32}\selectfont3}
对我有用的
只需在声明中移动字体内容,我就能得到想要的结果。大字体,以及控制间距的能力,就像我应该能够做到的那样:
\titleformat{\section}[wrap]{}{\thesection.}{.5em}{\vskip-1em\fontfamily{ptm}\fontsize{24}{24}\selectfont}
我把字体从<格式>部分<之前>部分。出于某种原因,声明大字体大小对我来说效果更好。
\titleformat{<命令>}[<形状>][<格式>}{<标签>}{<九月>}{<之前>}[<之后>]
在哪里<格式>应用于整个标题(标签和文本),并且<之前>是标题正文前面的代码。
现在 titlesec 中的间距内容按我预期的方式工作(我在最终结果中对此进行了调整):
\titlespacing{\section}{6pt}{-2ex plus .1ex minus .1ex}{6pt}
如果我需要调整间距,我只需更改该{-2ex plus .1ex minus .1ex}
部分。