
我正在排版一本書,其中有可愛的章節標題藝術作品以及每個部分的整頁藝術作品(因此第 1 部分獲得包含文本“第 1 部分”等的藝術作品)我成功地抑制了章節標題:
\newcommand{\mychapter}[1]{%
\begingroup
\let\@makechapterhead\@gobble % make \@makechapterhead do nothing
\chapter{#1}
\endgroup
}
(這確實有效,但 Koma 抱怨 @makechapterhead 的重新定義。我現在對此表示同意,但理想情況下我想要一個不會惹惱 Koma 的解決方案。)
但是,我想對 \part 和 \chapter 做同樣的事情,但我無法讓它工作。
這是一個 MWE,其中目錄和頁面跨度恰到好處,但我不希望列印帶有「第 1 部分」的頁面或其對面的空白頁:
\documentclass[twoside,chapterprefix,headings=big]{scrbook}
\usepackage{blindtext}
\usepackage{mwe}
\makeatletter
\newcommand{\mychapter}[1]{%
\begingroup
\let\@makechapterhead\@gobble
\chapter{#1}
\endgroup
}
\makeatother
\begin{document}
\tableofcontents
\KOMAoptions{headings=openleft}
\part{It begins}
%beautiful artwork goes... around here somewhere?
\includegraphics[width=\textwidth]{example-image-golden}
\KOMAoptions{headings=openright}
\mychapter{a chapter}
\begin{figure}[t!]
\centering
%beautiful chapter head artwork goes here
\includegraphics[width=\textwidth]{example-image-a}
\end{figure}
\blindtext
\mychapter{another chapter}
\begin{figure}[t!]
\centering
%beautiful chapter head artwork goes here
\includegraphics[width=\textwidth]{example-image-b}
\end{figure}
\blindtext
\KOMAoptions{headings=openleft}
\part{The middle bit}
%beautiful artwork goes... around here somewhere?
\includegraphics[width=\textwidth]{example-image-golden}
\KOMAoptions{headings=openright}
\mychapter{yet another chapter}
\includegraphics[width=\textwidth]{example-image-c}
\blindtext
\end{document}
(我們假裝「金色」圖像是用來代替 LaTeX 輸出「第 N 部分:標題」的整頁圖稿。)
我想要包含“第 N 部分:標題”的頁面及其對面的空白頁被抑制(不打印)。文件應直接從目錄展開為兩頁跨頁,零件圖稿位於左側,章節從右側開始。
創建類似於 \mychapter 的 \newcommand 似乎沒有做任何事情,甚至沒有在日誌中放入任何有趣的內容:
\makeatletter
\newcommand{\mypart}[1]{%
\begingroup
\let\@makeparthead\@gobble
\part{#1}
\endgroup
}
\makeatother
試圖偽造一個零件省略命令\part{It Begins}
,而不是摻雜 ToC
\addcontentsline{toc}{part}{Part \thepart: It Begins}
結果部分標題顯示在目錄中以下第 1 章,沒有零件編號,而且我不知道如何增加 \thepart 以便後續零件編號正確。嘗試手動增加它會\stepcounter{\thepart}
引發錯誤。
如果 Koma 的英文指南涵蓋了這一點,老實說我真的錯過了。
謝謝大家!
答案1
我不確定我是否完全理解你想要什麼。但我建議不要擺弄類別的內部結構,而是定義一個命令,它完全可以完成您想要的操作,而不是其他任何操作。據我所知你想要:
- 開始新的奇數頁(對於章節)或新的偶數頁(對於部分)
- 踏上櫃檯
- 可選新增目錄條目和頁首標記
- 列印影像
我對目錄條目和標記使用可選參數。我還定義了一個星形變體,而不增加數量,也沒有 TOC 條目和類似於\part*
和 的標記\chapter*
。我正在使用圖像檔案的強制參數:
\documentclass[chapterprefix,headings=big]{scrbook}
\usepackage{blindtext}
\usepackage{mwe}
\makeatletter
\NewDocumentCommand\ArtPart{som}{%
\cleardoubleevenpage
\IfBooleanTF{#1}{% star version: no TOC entry or page header
}{%
\refstepcounter{part}%
\IfValueTF{#2}{% optional argument: Use for TOC entry and page header
\addparttocentry{\thepart.}{#2}%
\partmark{#2}%
}{}%
}%
\noindent\includegraphics[width=\textwidth]{#3}%
\par\nobreak
\@afterindentfalse% don't indent first paragraph after the heading
\@afterheading% don't allow page break here etc.
}
\NewDocumentCommand\ArtChapter{som}{%
\cleardoubleoddpage
\IfBooleanTF{#1}{% star version: no TOC entry or page header
}{%
\refstepcounter{chapter}%
\IfValueTF{#2}{% optional argument: Use for TOC entry and page header
\addchaptertocentry{\thechapter}{#2}%
\chaptermark{#2}%
}{}%
}%
\noindent\includegraphics[width=\textwidth]{#3}%
\par\nobreak
\@afterindentfalse% don't indent first paragraph after the heading
\@afterheading% don't allow page break here etc.
}
\makeatother
\begin{document}
\tableofcontents
\ArtPart[It begins]{example-image-golden}
\ArtChapter[a chapter]{example-image-a}
\blindtext
\ArtChapter[another chapter]{example-image-b}
\blindtext
\ArtPart[The middle bit]{example-image-golden}
\ArtChapter[yet another chapter]{example-image-c}
\blindtext
\end{document}
另請注意,這\thepart
不是計數器,而是計數器的輸出。計數器將是part
,因此要操縱計數器,您必須使用\stepcounter{part}
, \refstepcounter{part}
, \addtocounter{part}{…}
, 和\setcounter{part}{…}
,但不是\stepcounter{\thepart}
。另請注意, \@makeparthead
KOMA-Script 中沒有預先定義。
有關更多信息,\NewDocumentCommand
請參閱“作者的 LaTeX — 目前版本”。有關所使用的 KOMA-Script 命令的更多信息,請參閱 KOMA-Script 手冊。
如果你真的想使用\part
and ,\chapter
恕我直言,你應該重新定義\chapterlineswithprefixformat
and\partlineswithprefixformat
而不是內部命令:
\documentclass[chapterprefix,headings=big]{scrbook}
\usepackage{blindtext}
\usepackage{mwe}
\newcommand\mypart[2]{%
\begingroup
\KOMAoption{open}{left}%
\renewcommand*{\partlineswithprefixformat}[3]{%
\includegraphics[width=\textwidth]{#2}% this is the second argument of
% \mypart not of \partlineswithprefixformat
}%
\renewcommand*{\partheademptypage}{}% don't add an empty page after \part
\part[#1]{#2}%
\endgroup
}
\newcommand\mychapter[2]{%
\KOMAoption{open}{right}%
\DeclareCommandCopy\ChapterLinesWithPrefixFormat\chapterlineswithprefixformat
\renewcommand*{\chapterlineswithprefixformat}[3]{%
\includegraphics[width=\textwidth]{#2}% this is the second argument of
% \mychapter not of \chapterlineswithprefixformat
}%
\chapter[#1]{#2}%
\DeclareCommandCopy\chapterlineswithprefixformat\ChapterLinesWithPrefixFormat
}
\begin{document}
\tableofcontents
\mypart{It begins}{example-image-golden}
\mychapter{a chapter}{example-image-a}
\blindtext
\mychapter{another chapter}{example-image-b}
\blindtext
\mypart{The middle bit}{example-image-golden}
\mychapter{yet another chapter}{example-image-c}
\blindtext
\end{document}
有了這個,您仍然可以使用\RedeclareSectionCommand
,例如,更改標題之前和之後的垂直距離=圖像之前和之後的垂直距離。
正如您所看到的,對於第二個建議,我不需要任何內部命令,而只需要 KOMA-Script 手冊中記錄的命令供用戶或高級用戶使用,或記錄在“作者的 LaTeX — 目前版本”。
注意:我沒有使用\begingroup…\endgroup
in \mychapter
,因為這也會破壞添加\label
after 的可能性\mychapter
,也會破壞afterindent=false
的功能\RedeclareSectionCommand
。相反,我存儲了\chapterlineswithprefixformat
before的含義\chapter
並在 after 後恢復了它\chapter
。
對於第一個建議,我只需要 LaTeX 核心中的\@afterindentfalse
和。\@afterheading
這些是類別/套件作者的常用命令,但不是內部 KOMA-Script 命令。