我正在尝试创建一种花哨的论文风格,但我被困在了目录中。我采用了 Pluton 的想法如何使用 TikZ 自定义目录?但我收到一条错误信息
! Missing $ inserted. <inserted text> l.1 ...ter}{\numberline
{1}From the Ground Up!}{3}LaTeX Font Warning: Command \large invalid
in math mode on input line 1. LaTeX Font Warning: Command \sc invalid
in math mode on input line 1. ! LaTeX Error: Command \bfseries invalid
in math mode.
我没有使用任何数学模式,所以我不明白这是从哪里来的。我的代码如下
\documentclass{book}
\usepackage[english,greek]{babel}
\usepackage[iso-8859-7]{inputenc}
\usepackage{kerkis}
\usepackage{pifont}
\usepackage[explicit]{titlesec}
\usepackage{kerkis}
\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{epigraph}
\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}
%--------------This is for chapter marks ------------------------
\usepackage{background}
\usetikzlibrary{calc}
\usepackage{xifthen}
\usepackage{totcount}
\regtotcounter{chapter}
\backgroundsetup%
{ contents={%
\begin{tikzpicture}[overlay]
\pgfmathtruncatemacro{\mytotalchapters}{\totvalue{chapter} > 0 ? \totvalue{chapter} : 20}
\pgfmathsetmacro{\mypaperheight}{\paperheight/28.453}
\pgfmathsetmacro{\mytop}{-(\thechapter-1)/\mytotalchapters*\mypaperheight}
\pgfmathsetmacro{\mybottom}{-\thechapter/\mytotalchapters*\mypaperheight}
\ifcase\thechapter
\xdef\mycolor{white}
\or \xdef\mycolor{red}
\or \xdef\mycolor{orange}
\or \xdef\mycolor{yellow}
\or \xdef\mycolor{green}
\or \xdef\mycolor{blue}
\or \xdef\mycolor{violet}
\else \xdef\mycolor{black}
\fi
\ifthenelse{\isodd{\value{page}}}
{\fill[\mycolor] ($(current page.north east)+(0,\mytop)$) rectangle ($(current page.north east)+(-0.5,\mybottom)$);}
{\fill[\mycolor] ($(current page.north west)+(0,\mytop)$) rectangle ($(current page.north west)+(0.5,\mybottom)$);}
\end{tikzpicture}
},
scale=1,
angle=0
}
%-------------------This for fancy ToC---------------------
\definecolor{doc}{RGB}{0,60,110}
\contentsmargin{0cm}
\titlecontents{chapter}[0pc]
{\addvspace{30pt}%
\begin{tikzpicture}[remember picture, overlay]%
\draw[fill=doc!30,draw=doc!30, rounded corners] (-4,-.1) rectangle (-1,.5);%
\pgftext[left,x=-3.7cm,y=0.2cm]{\color{white}\Large\sc\bfseries chapter\ \thecontentslabel};%
\end{tikzpicture}\color{doc!40}\large\sc\bfseries}%
{}
{}
{\;\titlerule\;\large\sc\bfseries Page \thecontentspage
\begin{tikzpicture}[remember picture, overlay]
\draw[fill=doc!25,draw=doc!20, rounded corners=0pt] (2pt,0) rectangle (6,0.1pt);
\end{tikzpicture}}%
\titlecontents{section}[2.4pc]
{\addvspace{1pt}}
{\contentslabel[\thecontentslabel]{2.4pc}}
{}
{\hfill\small \thecontentspage}
[]
\titlecontents*{subsection}[4pc]
{\addvspace{-1pt}\small}
{}
{}
{\ --- \small\thecontentspage}
[ \textbullet\ ][]
\makeatletter
\renewcommand{\tableofcontents}{%
\chapter*{%
\vspace*{-20\p@}%
\begin{tikzpicture}[remember picture, overlay]%
\pgftext[right,x=15cm,y=0.2cm]{\color{doc!30}\Huge\sc\bfseries \contentsname};%
\draw[fill=doc!30,draw=doc!30, rounded corners=15pt] (13,-.75) rectangle (20,1);%
\clip (13,-.75) rectangle (20,1);
\pgftext[right,x=15cm,y=0.2cm]{\color{white}\Huge\sc\bfseries \contentsname};%
\end{tikzpicture}}%
\@starttoc{toc}}
\makeatother
\begin{document}
\tableofcontents
\chapter{From the Ground Up!}
\epigraph{In theory there is no difference \\ between theory and practice. \\ In practice there is.}{Lawrence ``Yogui'' Berra,1925 \\ New York Yankees baseball player}
\DoPToC
\chapter*{A test unnumbered chapter}
\DoPToC
\chapter{Another chapter}
\epigraph{In theory there is no difference \\ between theory and practice. \\ In practice there is.}{Lawrence ``Yogui'' Berra,1925 \\ New York Yankees baseball player}
\DoPToC
\section{A simple section}
\section{Another simple section}
\end{document}
我认为我确信花式篇章和精美的目录但我不知道如何找到它。有人知道发生了什么吗?
答案1
问题在于 for 的最后一个强制参数,\titlecontents
其中chapter
您使用的\;
是一个仅限数学模式的空间,并且您试图在文本模式下使用它;将它们替换为文本模式空间。
我使用“%问题在这里”标记了下面有问题的行,这样您就可以轻松地看到问题出在哪里并可以应用必要的更正:
\titlecontents{chapter}[0pc]
{\addvspace{30pt}%
\begin{tikzpicture}[remember picture, overlay]%
\draw[fill=doc!30,draw=doc!30, rounded corners] (-4,-.1) rectangle (-1,.5);%
\pgftext[left,x=-3.7cm,y=0.2cm]{\color{white}\Large\scshape\bfseries chapter\ \thecontentslabel};%
\end{tikzpicture}\color{doc!40}\large\sc\bfseries}%
{}
{}
{\;\titlerule\;% the problem is here
\large\scshape\bfseries Page \thecontentspage
\begin{tikzpicture}[remember picture, overlay]
\draw[fill=doc!25,draw=doc!20, rounded corners=0pt] (2pt,0) rectangle (6,0.1pt);
\end{tikzpicture}}%
因为你不是自然地处于数学模式,而不是错误的
\;\titlerule\;
你可以使用
\enspace\titlerule\enspace
或者
\hspace*{6pt}\titlerule\hspace*{6pt}
更改6pt
为适合您需要的长度。