创建“自己的”部分页面

创建“自己的”部分页面

首先,我对我的英语水平感到抱歉。

我尝试在包含在 main.tex 中的新 .tex 文档中创建自己的部分页面:

\stepcounter{part}
\addcontentsline{toc}{part}{\thepart.\hspace{1em}NamePart}

\begin{titlepage}
    \centering
    {\hspace{1pt}}
    \par \vspace{4cm}
    {\huge \sffamily \bfseries \thepart. NamePart}
    \par \vspace{1cm}
    \includegraphics[scale=0.3]{SomePicture}
    \par \vspace{0.5cm}
    {\textcolor{red}{\rule{0.7\textwidth}{2pt}}}
    !here!
    {\textcolor{red}{\rule{0.7\textwidth}{2pt}}}
\end{titlepage}

主要.tex:

\documentclass[a4paper,11pt,oneside]{scrbook}
\usepackage[ngerman]{babel}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{csquotes}
\begin{document}
\tableofcontents
\include{document with the code above}
\chapter{Chapter One}
\section{Section One}
\section{Section Two}
\chapter{Chapter Two}
\section{Section Three}
\end{document}

但这样我遇到了多个问题:

  • 未打印页码
  • 在目录中显示了条目,但 hyperef 不起作用
  • 我想为该部分添加一个小的目录(我在代码中标记了!这里!)但我不知道该怎么做

答案1

不要将titlepage环境误用为部分页面。您的类是 KOMA-Script 类,因此您可以重新定义\partlineswithentryprefix。对于部分目录,您可以加载包etoc

例子:

\documentclass[a4paper,11pt,oneside]{scrbook}
\usepackage[ngerman]{babel}
%\usepackage[utf8]{inputenc}% needed with older TeX distributions
\usepackage[T1]{fontenc}
\usepackage{csquotes}
\usepackage{xcolor}
\usepackage{graphicx}
\usepackage{etoc}
\usepackage{hyperref}

\RedeclareSectionCommand[beforeskip=4cm]{part}
\renewcommand\partformat{\thepart\autodot\enskip}
\renewcommand\partheadmidvskip{}
\addtokomafont{part}{\huge}
\renewcommand\partlineswithprefixformat[3]{%
  #2#3
  \ifstr{#1}{part}{%
    \par \vspace{1cm}
    \centering
    \includegraphics[scale=.3]{example-image}\par
    {\textcolor{red}{\rule{0.7\textwidth}{2pt}}}\par
    \etocsettocstyle{}{}%
    %\etocsettocdepth{\chaptertocdepth}%
    {\normalsize\localtableofcontents}
    {\textcolor{red}{\rule{0.7\textwidth}{2pt}}}\par
  }{}%
}
\begin{document}
\tableofcontents
\part{NamePart}
\chapter{Chapter One}
\section{Section One}
\section{Section Two}
\chapter{Chapter Two}
\section{Section Three}
\part{NextPart}
\chapter{Chapter Three}
\end{document}

结果:

在此处输入图片描述


如果有不同部位用不同图片或者部分页面没有图片,那么可以定义一个图片文件名称的宏:

\newcommand*\partimage{example-image}
\newcommand\setpartimage[1]{\def\partimage{#1}}

然后你必须将\includegraphics行改为

\ifstr{\partimage}{}{}{\includegraphics[scale=.3]{\partimage}\par}%

例子:

\documentclass[a4paper,11pt,oneside]{scrbook}
\usepackage[ngerman]{babel}
%\usepackage[utf8]{inputenc}% needed with older TeX distributions
\usepackage[T1]{fontenc}
\usepackage{csquotes}
\usepackage{xcolor}
\usepackage{graphicx}
\usepackage{etoc}
\usepackage{hyperref}

\RedeclareSectionCommand[beforeskip=4cm]{part}
\renewcommand\partformat{\thepart\autodot\enskip}
\renewcommand\partheadmidvskip{}
\addtokomafont{part}{\huge}
\renewcommand\partlineswithprefixformat[3]{%
  #2#3
  \ifstr{#1}{part}{%
    \par \vspace{1cm}
    \centering
    \ifstr{\partimage}{}{}{\includegraphics[scale=.3]{\partimage}\par}%
    {\textcolor{red}{\rule{0.7\textwidth}{2pt}}}\par
    \etocsettocstyle{}{}%
    %\etocsettocdepth{\chaptertocdepth}%
    {\normalsize\localtableofcontents}
    {\textcolor{red}{\rule{0.7\textwidth}{2pt}}}\par
  }{}%
}
\newcommand*\partimage{example-image}
\newcommand\setpartimage[1]{\def\partimage{#1}}

\begin{document}
\tableofcontents
\setpartimage{example-image-a}
\part{NamePart}
\chapter{Chapter One}
\section{Section One}
\section{Section Two}
\chapter{Chapter Two}
\section{Section Three}
\setpartimage{example-image-b}
\part{NextPart}
\chapter{Chapter Three}
\setpartimage{}
\part{Part without picture}
\chapter{Chapter Four}
\end{document}

结果:

在此处输入图片描述

在此处输入图片描述

在此处输入图片描述

相关内容