使用 \include{} 加载前导代码时出现故障

使用 \include{} 加载前导代码时出现故障

我正在尝试使用 加载一段代码\include{file}。此代码用于tikz创建精美的章节。奇怪的是,当我加载代码时, 被\chaptername切断(运行代码两次后),如下图所示。

在此处输入图片描述

但是,如果我直接将代码放在序言中并运行两次,它就可以正常工作!

在此处输入图片描述

我无法想出导致此故障的任何逻辑原因。您知道可能出现什么问题以及如何修复吗?

我的代码是

main.tex

\documentclass{book}

\usepackage{etex}%Makes able the use of many packages
\include{Preamble/fancyChapter}

\begin{document}

  \chapter{rkbnjg}
  %\eng{Hello world}, Γεια σου κόσμε\\

\end{document}

fancyChapter.tex

\usepackage[english,greek]{babel}
\usepackage[iso-8859-7]{inputenc}
\usepackage{kerkis}
\usepackage{pifont}
\usepackage[explicit]{titlesec}

\usepackage{tikz}
\usepackage{epigraph}
\usepgflibrary{qrr.shapes.openrectangle}

\definecolor{mybluei}{RGB}{0,173,239}
\definecolor{myblueii}{RGB}{63,200,244}
\definecolor{myblueiii}{RGB}{199,234,253}

\tikzset{
mynode/.style={
  rounded corners=30pt,
  shape=open rectangle,
  open rectangle fill=myblueii,
  open rectangle sides=#1,
  }
}

\titleformat{\chapter}[display]
  {\normalfont\huge\sffamily}
  {}
  {20pt}
  {%
  \begin{tikzpicture}[remember picture,overlay]
  \node[
    anchor=west,
    rectangle,
    minimum height=4cm,
    text width=\paperwidth,
    xshift=-\the\dimexpr\oddsidemargin+1in\relax,
    outer sep=0pt,
    fill=myblueiii] (titlerect) {};
  \node[
    anchor=south west,
    xshift=2cm,
    text width=\textwidth] 
    at ([yshift=5pt]titlerect.south west) {\fontsize{30}{36}\selectfont#1};
  \node[
    mynode=nw,
    anchor=south east,
    fill=myblueii,
    inner xsep=1.5cm,
    outer sep=0pt,
    font=\color{white},
    minimum height=30pt] 
    at (current page.east|-titlerect.north)
     {\bfseries\MakeUppercase{\chaptertitlename}\ \thechapter};
  \end{tikzpicture}%
  }
\titleformat{name=\chapter,numberless}[display]
  {\normalfont\huge\sffamily}
  {}
  {20pt}
  {%
  \begin{tikzpicture}[remember picture,overlay]
  \node[
    anchor=west,
    rectangle,
    minimum height=4cm,
    text width=\paperwidth,
    xshift=-\the\dimexpr\oddsidemargin+1in\relax,
    outer sep=0pt,
    fill=myblueiii] (titlerect) {};
  \node[
    anchor=south west,
    xshift=2cm,
    text width=\textwidth] 
    at (titlerect.south west) {\Huge#1};
  \end{tikzpicture}%
  }
\titlespacing*{\chapter}
  {0pt}{-20pt}{60pt}

\usepackage[margin=2.8cm]{geometry}

\setlength\beforeepigraphskip{1.5\baselineskip}
\setlength\afterepigraphskip{2\baselineskip}
\setlength\epigraphwidth{6.8cm}
\setlength\epigraphrule{0.1pt}
\renewcommand\epigraphsize{\large}
\renewcommand\textflush{flushright}

\let\oldepigraph\epigraph \renewcommand\epigraph[2]{%
  \oldepigraph{\color{blue}\itshape #1}{#2}}

\usepackage{titletoc}
\newcommand\DoPToC{%
\startcontents\printcontents{}{1}{\noindent{\color{blue}\rule{\textwidth}{.5pt}}\par\medskip}}
\usepackage{xpatch}

答案1

不能\include在序言中使用,请改用\input

\include除了直接复制文件内容之外,它还做了更多的事情,例如,它发出一个\clearpage,这显然不属于序言。

另一种可能性是编写一个新包并加载它usepackage,或者编写一个新类。

相关内容