分页 #
自动分页 #
有时你可能想导出到 PDF,并在所有 top-level headings (opens new window) ,也许总是把标题放在右边的页面上。
顶级标题是用单前缀 #
(和可选的后缀)或等号下划线 ====
;两者在 HTML 输出中都产生 <h1>
。二级标题是用双散列前缀 ##
,或用连字符减去下划线 ----
;两者都产生 <h2>
。第三级 ###
到第六级 ######
的标题没有备选的下划线语法,分别产生 HTML 元素 <h3>
到 <h6>
。
要在标题前添加自动分页,请打开 themes folder (opens new window) ,并编辑 respective CSS file (opens new window) 。
@media print, (overflow-block: paged) or (overflow-block: optional-paged)
{
/* Move top-level headings to a new page on the right-hand side: */
h1
{
page-break-before: right; /* CSS 2 */
break-before: recto; /* CSS 3+,
also works for languages written and paginated right-to-left */
}
/* Override the previous ruleset for the very first heading: */
h1:first-of-type,
section > h1:first-child
{
page-break-before: avoid; /* CSS 2 */
break-before: avoid; /* CSS 3+ */
}
/* Force second-level headings to begin in a new column or
possiblyon a new page if it was in the last of multiple columns otherwise: */
h2
{
break-before: column;
}
/* Headings should not be the last paragraph on a page: */
h1, h2, h3, h4, h5, h6
{
page-break-after: avoid;
}
/* Consecutive headings with deepening level should not be split across pages: */
h1+h2, h2+h3, h3+h4, h4+h5, h5+h6
{
page-break-before: avoid;
}
}
现在,当导出时,在每个顶层标题之前至少会创建一个新的页面,除了第一个页面。
然而,这通常需要先将 Markdown 文件转换为 HTML,然后再转换为 PDF 或打印。如果从中间的 LaTeX 转换到 PDF,它可能不会像预期的那样工作,就像 Pandoc 默认的那样。
强制分页 #
有几种方法可以使用自定义 CSS 在文档中插入一个手动分页。
HTML 和 Inline CSS #
如果只需要一次,样式规则可以嵌入到位。
Markdown with embedded HTML:
<div style="page-break-after: always; break-after: page;"></div>
Markdown continues.
<p>Markdown with embedded HTML:</p>
<div style="page-break-after: always; break-after: page;"></div>
<p>Markdown continues.</p>
HTML 和中央 CSS #
如果经常需要手动分页,使用 external stylesheet (opens new window) 更有意义,可以更好地维护和减少杂乱。
Markdown with embedded HTML:
<div class="page-break"></div>
Markdown continues.
<p>Markdown with embedded HTML:</p>
<div class="page-break"></div>
<p>Markdown continues.</p>
/* completely hide the element where it is not needed */
.page-break
{
display: none;
}
@media print, (overflow-block: paged) or (overflow-block: optional-paged)
{
.page-break
{
display: block;
page-break-after: always; /* CSS 2 */
break-after: page; /* CSS 3+ */
}
}
主题性休息 #
另外,现有的 Markdown 结构也可以被重新利用。这样一来,在 Markdown 文件中既不需要 HTML 也不需要 CSS。
有三种方法可以插入 thematic break in Markdown (opens new window),使用三个或更多的星号 *
,连字符 -
,或下划线 _
,可能在它们之间还有空白。它们都会产生相同的 HTML(或 PDF)输出,然后可以用来创建分页符。基本上所有的 Markdown 演示包也都遵循这个惯例,为每一个主题中断插入一个幻灯片过渡。
Break incoming
* * *
in between breaks
----
still one more to come
___________
after the final break.
<p>Break incoming</p>
<hr>
<p>in between breaks</p>
<hr>
<p>still one more to come</p>
<hr>
<p>after the final break.</p>
唯一需要的是 some custom CSS (opens new window) 。
@media print, (overflow-block: paged) or (overflow-block: optional-paged)
{
hr
{
page-break-after: always; /* CSS 2 */
break-after: region; /* CSS 3+ */
/* minimal layout disruption: */
height: 0.1mm; visibility: hidden;
}
}
CSS 详细信息 #
CSS Level 3 (opens new window) 和,使用比,更通用的方法将内容分解成页面等。later (opens new window) CSS Level 2 (opens new window)
break-after|before: auto > page-break-after|before: auto
| avoid
| avoid-page = page-break-after|before: avoid
| avoid-column
| avoid-region
| page = page-break-after|before: always
| left = page-break-after|before: left
| right = page-break-after|before: right
| recto | verso
| column
| region
break-inside: auto > page-break-inside: auto
| avoid
| avoid-page = page-break-inside: avoid
| avoid-column
| avoid-region