删除部分标题上方和下方的多余空间

删除部分标题上方和下方的多余空间

我正在用 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É (generic)”,但似乎您不希望这样。但是如果您愿意,您也可以在标题页中删除\let\strut\relax并添加一个\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。但是,它表明,定义新的分段样式可能非常容易。

相关内容