Я пишу лекции в 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 всегда добавляет a \strut
в конец текста заголовка части, чтобы иметь одинаковую высоту и глубину, например, «ace» и «ACÉ (generic)», но, похоже, вам это не нужно. Но если вы хотите, вы можете в качестве альтернативы удалить \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}
BTW: Теоретически 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
. Однако он показывает, что определение новых стилей секционирования может быть очень простым.