我正在用 LaTeX 編寫講義,並且我想遵循我所就讀的大學的《企業設計指南》中規定的一些格式指南。特別是,我想設定我的標題頁和插入在每個標題頁開頭的頁面部分以一種非常具體的方式。為此,我使用 TikZ 和 TikZ 庫calc
來正確定位這些頁面上的各個部分。
這是我面臨的問題:我% TEXTBOX
在下面的 MWE 中標記的內容的位置相對於我% (SUB-)HEADLINE
在 MWE 中標記的內容的頂部/底部。在我的扉頁上,這工作得很好。我的意思是,組件中包含文字的框在% (SUB-)HEADLINE
實際文字的正上方和正下方開始和結束。然而,對於\part{...}
每個部分開頭的命令引入的頁面,% HEADLINE
該部分頁面的文本上方和下方似乎有額外的空間。當我操作命令的第二個參數時,此空間量會發生變化\fontsize{}{}
,並且行為會有所不同,具體取決於部分標題是跨一行還是跨兩行(如 MWE 中所示)。請注意,命令中選擇的值\fontsize
不是任意的,而是在我打算遵循的樣式指南中固定的。因此,如果可能的話,我寧願不改變這些。
我花了相當多的時間試圖找到這個問題的答案,並遇到了以下命令:
partheadstartvskip
partheadendvskip
RedeclareSectionCommand[...]{part}
以及選項/參數beforeskip
,afterskip
,innerskip
然而,使用這些,我一直無法擺脫額外的空間部分我的扉頁上沒有的頁面。
非常感謝對此的任何幫助!
\documentclass[paper=a4, fontsize=11pt]{scrbook}
\usepackage{tikz}
\usetikzlibrary{calc}
\usepackage{setspace}
% MODIFY APPEARANCE OF PART PAGES
\renewcommand\partformat{%
\fontsize{12pt}{14pt}\selectfont%
\partname~\thepart%
}
\setkomafont{part}{\fontsize{24pt}{34pt}\selectfont}
\renewcommand\partlineswithprefixformat[3]{%
\thispagestyle{empty}%
\begin{tikzpicture}[remember picture, overlay]
% HEADLINE
\node[rectangle, anchor=south west, inner sep=0pt, text width=130mm, text=white] (headline) at ($(current page.south west) + (16mm, 72mm)$) {#3};
% SUBHEADLINE
\node[rectangle, anchor=south west, inner sep=0pt, text width=130mm, text=white] (subheadline) at ($(headline.north west) + (0, 16mm)$) {#2};
% BACKGROUND
\fill[lightgray] ($(current page.north west) + (8mm, -38mm)$) rectangle ($(current page.east |- subheadline.north) + (0, 16mm)$);
% TEXTBOX
\fill[gray, fill opacity=0.9] ($(current page.west |- subheadline.north) + (0mm, 32mm)$) rectangle ($(current page.west |- headline.south) + (154mm, -16mm)$);
% HEADLINE
\node[rectangle, anchor=south west, inner sep=0pt, text width=130mm, text=white, draw] at (headline.south west) {#3};
% SUBHEADLINE
\node[rectangle, anchor=south west, inner sep=0pt, text width=130mm, text=white, draw] at (subheadline.south west) {#2};
\end{tikzpicture}
}
\begin{document}
\sffamily
\onehalfspacing
% TITLE PAGE
\begin{titlepage}
\begin{tikzpicture}[remember picture, overlay]
% BACKGROUND
\fill[lightgray] ($(current page.north west) + (8mm, -38mm)$) rectangle ($(current page.south east)$);
% HEADLINE
\node[rectangle, anchor=south west, inner sep=0pt, text width=130mm, text=white] (headline) at ($(current page.south west) + (16mm, 32mm)$) {\fontsize{24pt}{34pt}\selectfont \sffamily\bfseries Quantitative Foundations of \\ Artificial Intelligence \par};
% SUBHEADLINE
\node[rectangle, anchor=south west, inner sep=0pt, text width=130mm, text=white] (subheadline) at ($(headline.north west) + (0, 8mm)$) {\fontsize{12pt}{14pt}\selectfont \sffamily\bfseries Name of University \textbar{} Winter 2023/24 \par};
% TEXTBOX
\fill[gray, fill opacity=0.9] ($(current page.west |- subheadline.north) + (0mm, 16mm)$) rectangle ($(current page.south west) + (154mm, 16mm)$);
% HEADLINE
\node[rectangle, anchor=south west, inner sep=0pt, text width=130mm, text=white, draw] at (headline.south west) {\fontsize{24pt}{34pt}\selectfont \bfseries Quantitative Foundations of \\ Artificial Intelligence \par};
% SUBHEADLINE
\node[rectangle, anchor=south west, inner sep=0pt, text width=130mm, text=white, draw] at (subheadline.south west) {\fontsize{12pt}{14pt}\selectfont \bfseries Name of University \textbar{} Winter 2023/24 \par};
\end{tikzpicture}
\end{titlepage}
\part{Quantitative Foundations of Artificial Intelligence}
\part{Quantitative Foundations}
\end{document}
答案1
如果您希望標題頁和部分標題具有相同的格式,我建議對兩者使用相同的程式碼:
\documentclass[paper=a4, fontsize=11pt]{scrbook}
\usepackage{tikz}
\usetikzlibrary{calc}
\usepackage{setspace}
% MODIFY APPEARANCE OF PART PAGES
\renewcommand\partformat{%
\partname~\thepart%
}
% You can do the font selection in the TikZ code below,
% and then either don't change the fontsize here (or
% use \normalsize) would be enough.
\setkomafont{part}{}
\setkomafont{partnumber}{}
% You also do all the distances in the TikZ code, so
% not adding additional distances by the part heading itself
% would be suggested.
\RedeclareSectionCommand[beforeskip=0pt,innerskip=0pt,afterskip=0pt]{part}
\newcommand{\TikZTitle}[2]{%
\begin{tikzpicture}[remember picture, overlay]
% BACKGROUND
\fill[lightgray] ($(current page.north west) + (8mm, -38mm)$) rectangle ($(current page.south east)$);
% HEADLINE
\node[rectangle, anchor=south west, inner sep=0pt, text width=130mm, text=white] (headline) at ($(current page.south west) + (16mm, 32mm)$) {\fontsize{24pt}{34pt}\let\strut\relax\sffamily\bfseries #2\par};
% SUBHEADLINE
\node[rectangle, anchor=south west, inner sep=0pt, text width=130mm, text=white] (subheadline) at ($(headline.north west) + (0, 8mm)$) {\fontsize{12pt}{14pt}\sffamily\bfseries #1\par};
% TEXTBOX
\fill[gray, fill opacity=0.9] ($(current page.west |- subheadline.north) + (0mm, 16mm)$) rectangle ($(current page.south west) + (154mm, 16mm)$);
% HEADLINE
\node[rectangle, anchor=south west, inner sep=0pt, text width=130mm, text=white, draw] at (headline.south west) {\fontsize{24pt}{34pt}\bfseries\let\strut\relax #2\par};
% SUBHEADLINE
\node[rectangle, anchor=south west, inner sep=0pt, text width=130mm, text=white, draw] at (subheadline.south west) {\fontsize{12pt}{14pt}\bfseries #1\par};
\end{tikzpicture}
}
\renewcommand\partlineswithprefixformat[3]{%
\thispagestyle{empty}%
\TikZTitle{#2}{#3}%
}
\begin{document}
\sffamily
\onehalfspacing
% TITLE PAGE
\begin{titlepage}
\TikZTitle{Name of University \textbar{} Winter 2023/24}
{Quantitative Foundations of \\ Artificial Intelligence }
\end{titlepage}
\part[{Quantitative Foundations of Artificial Intelligence}]{Quantitative Foundations of \\ Artificial Intelligence}
\part{Quantitative Foundations}
\end{document}
以下是僅奇數頁的結果:
我已經添加\let\strut\relax
到這個解決方案中,因為 KOMA-Script 總是\strut
在部分標題文本的末尾添加一個,以具有相同的高度和深度,例如“ace”和“ACÉ(通用)”,但它看來,你不想要這個。但如果您願意,您也可以刪除\let\strut\relax
並在標題頁中添加 a\strut
和參數末尾:
\documentclass[paper=a4, fontsize=11pt]{scrbook}
\usepackage{tikz}
\usetikzlibrary{calc}
\usepackage{setspace}
% MODIFY APPEARANCE OF PART PAGES
\renewcommand\partformat{%
\partname~\thepart%
}
% You can do the font selection in the TikZ code below,
% and then either don't change the fontsize here (or
% use \normalsize) would be enough.
\setkomafont{part}{}
\setkomafont{partnumber}{}
% You also do all the distances in the TikZ code, so
% not adding additional distances by the part heading itself
% would be suggested.
\RedeclareSectionCommand[beforeskip=0pt,innerskip=0pt,afterskip=0pt]{part}
\newcommand{\TikZTitle}[2]{%
\begin{tikzpicture}[remember picture, overlay]
% BACKGROUND
\fill[lightgray] ($(current page.north west) + (8mm, -38mm)$) rectangle ($(current page.south east)$);
% HEADLINE
\node[rectangle, anchor=south west, inner sep=0pt, text width=130mm, text=white] (headline) at ($(current page.south west) + (16mm, 32mm)$) {\fontsize{24pt}{34pt}\sffamily\bfseries #2\par};
% SUBHEADLINE
\node[rectangle, anchor=south west, inner sep=0pt, text width=130mm, text=white] (subheadline) at ($(headline.north west) + (0, 8mm)$) {\fontsize{12pt}{14pt}\sffamily\bfseries #1\par};
% TEXTBOX
\fill[gray, fill opacity=0.9] ($(current page.west |- subheadline.north) + (0mm, 16mm)$) rectangle ($(current page.south west) + (154mm, 16mm)$);
% HEADLINE
\node[rectangle, anchor=south west, inner sep=0pt, text width=130mm, text=white, draw] at (headline.south west) {\fontsize{24pt}{34pt}\bfseries #2\par};
% SUBHEADLINE
\node[rectangle, anchor=south west, inner sep=0pt, text width=130mm, text=white, draw] at (subheadline.south west) {\fontsize{12pt}{14pt}\bfseries #1\par};
\end{tikzpicture}
}
\renewcommand\partlineswithprefixformat[3]{%
\thispagestyle{empty}%
\TikZTitle{#2}{#3}%
}
\begin{document}
\sffamily
\onehalfspacing
% TITLE PAGE
\begin{titlepage}
\TikZTitle{Name of University \textbar{} Winter 2023/24}
{Quantitative Foundations of \\ Artificial Intelligence\strut}
\end{titlepage}
\part[{Quantitative Foundations of Artificial Intelligence}]
{Quantitative Foundations of \\ Artificial Intelligence}
\part{Quantitative Foundations}
\end{document}
在這兩種情況下,標題頁和分頁之間的唯一區別是副標題的高度和深度,因為標題頁的副標題中有y
、|
、 和。/
為了避免這種差異,您可以添加\strut
字幕的用法:
\documentclass[paper=a4, fontsize=11pt]{scrbook}
\usepackage{tikz}
\usetikzlibrary{calc}
\usepackage{setspace}
% MODIFY APPEARANCE OF PART PAGES
\renewcommand\partformat{%
\partname~\thepart%
}
% You can do the font selection in the TikZ code below,
% and then either don't change the fontsize here (or
% use \normalsize) would be enough.
\setkomafont{part}{}
\setkomafont{partnumber}{}
% You also do all the distances in the TikZ code, so
% not adding additional distances by the part heading itself
% would be suggested.
\RedeclareSectionCommand[beforeskip=0pt,innerskip=0pt,afterskip=0pt]{part}
\newcommand{\TikZTitle}[2]{%
\begin{tikzpicture}[remember picture, overlay]
% BACKGROUND
\fill[lightgray] ($(current page.north west) + (8mm, -38mm)$) rectangle ($(current page.south east)$);
% HEADLINE
\node[rectangle, anchor=south west, inner sep=0pt, text width=130mm, text=white] (headline) at ($(current page.south west) + (16mm, 32mm)$) {\fontsize{24pt}{34pt}\sffamily\bfseries #2\par};
% SUBHEADLINE
\node[rectangle, anchor=south west, inner sep=0pt, text width=130mm, text=white] (subheadline) at ($(headline.north west) + (0, 8mm)$) {\fontsize{12pt}{14pt}\sffamily\bfseries\strut #1\par};
% TEXTBOX
\fill[gray, fill opacity=0.9] ($(current page.west |- subheadline.north) + (0mm, 16mm)$) rectangle ($(current page.south west) + (154mm, 16mm)$);
% HEADLINE
\node[rectangle, anchor=south west, inner sep=0pt, text width=130mm, text=white, draw] at (headline.south west) {\fontsize{24pt}{34pt}\bfseries #2\par};
% SUBHEADLINE
\node[rectangle, anchor=south west, inner sep=0pt, text width=130mm, text=white, draw] at (subheadline.south west) {\fontsize{12pt}{14pt}\bfseries\strut #1\par};
\end{tikzpicture}
}
\renewcommand\partlineswithprefixformat[3]{%
\thispagestyle{empty}%
\TikZTitle{#2}{#3}%
}
\begin{document}
\sffamily
\onehalfspacing
% TITLE PAGE
\begin{titlepage}
\TikZTitle{Name of University \textbar{} Winter 2023/24}
{Quantitative Foundations of \\ Artificial Intelligence\strut}
\end{titlepage}
\part[{Quantitative Foundations of Artificial Intelligence}]
{Quantitative Foundations of \\ Artificial Intelligence}
\part{Quantitative Foundations}
\end{document}
順便一提:理論上 KOMA-Script 也支援定義全新的切片樣式。不幸的是,目前還沒有此功能的官方文檔,可能是因為目前它需要定義內部命令:
\documentclass[paper=a4, fontsize=11pt]{scrbook}
\usepackage{tikz}
\usetikzlibrary{calc}
\usepackage{setspace}
% MODIFY APPEARANCE OF PART PAGES
\renewcommand\partformat{%
\partname~\thepart%
}
\newcommand{\TikZTitle}[2]{%
\begin{tikzpicture}[remember picture, overlay]
% BACKGROUND
\fill[lightgray] ($(current page.north west) + (8mm, -38mm)$) rectangle ($(current page.south east)$);
% HEADLINE
\node[rectangle, anchor=south west, inner sep=0pt, text width=130mm, text=white] (headline) at ($(current page.south west) + (16mm, 32mm)$) {\fontsize{24pt}{34pt}\sffamily\bfseries #2\par};
% SUBHEADLINE
\node[rectangle, anchor=south west, inner sep=0pt, text width=130mm,
text=white] (subheadline) at ($(headline.north west) + (0, 8mm)$)
{\fontsize{12pt}{14pt}\sffamily\bfseries #1\par};
% TEXTBOX
\fill[gray, fill opacity=0.9] ($(current page.west |- subheadline.north) + (0mm, 16mm)$) rectangle ($(current page.south west) + (154mm, 16mm)$);
% HEADLINE
\node[rectangle, anchor=south west, inner sep=0pt, text width=130mm, text=white, draw] at (headline.south west) {\fontsize{24pt}{34pt}\bfseries #2\par};
% SUBHEADLINE
\node[rectangle, anchor=south west, inner sep=0pt, text width=130mm, text=white, draw] at (subheadline.south west) {\fontsize{12pt}{14pt}\bfseries #1\par};
\end{tikzpicture}
}
\makeatletter
% This is used to set the style tikzpart of a command. The argument is the
% name of the command as used for \DeclareSectionCommand etc.
\newcommand*{\scr@dsc@def@style@tikzpart@command}[1]{%
\@namedef{#1}{\dotikzpart{#1}}%
}
% This makes a new heading of type tikzpart. The aruments are:
% #1: The name of the command (see \scr@dsc@def@style@tikzpart@command)
% #2: star or not (star is used for not numbered headings)
% #3: ToC entry (currently only used for numbered headings)
% #4: title
\NewDocumentCommand\dotikzpart{m s O{#4} m}
{
\cleardoubleoddpage\thispagestyle{empty}%
\IfBooleanTF{#2}{%
\TikZTitle{}{#4}%
}{%
\refstepcounter{#1}%
\@nameuse{add#1tocentry}{\@nameuse{the#1}}{#3}%
\TikZTitle{\csname #1format\endcsname}{#4}%
}%
\clearpage
}
\makeatother
\RedeclareSectionCommand[style=tikzpart]{part}% use the new style for \part
\begin{document}
\sffamily
\onehalfspacing
\tableofcontents
% TITLE PAGE
\begin{titlepage}
\TikZTitle{Name of University \textbar{} Winter 2023/24}
{Quantitative Foundations of \\ Artificial Intelligence}
\end{titlepage}
\part[{Quantitative Foundations of Artificial Intelligence}]
{Quantitative Foundations of \\ Artificial Intelligence}
\part{Quantitative Foundations}
\end{document}
注意:這是一個非常基本的範例。例如,它不支援原始 KOMA-Script 的擴充可選參數\part
。然而,它表明,定義新的剖面樣式可能非常容易。