我需要为书籍添加一个看起来漂亮的章节起始页。我们使用类memoir
并利用它制作tikz
漂亮的章节标题。现在,我需要在章节起始页上添加章节中出现的章节列表。我尝试过使用类似以下方法:
\documentclass[oneside]{memoir}
\usepackage{tikz}
\usepackage{titletoc}
\usepackage{lipsum}
\begin{document}
\tableofcontents
\chapter{A chapter}
\startcontents[chapters]
\begin{tikzpicture}[overlay]
\node[fill=blue] {\printcontents[chapters]{}{1}{}};
\end{tikzpicture}
\section{Section}
\lipsum[1]
\section{Section 2}
\lipsum
\chapter{Second chapter}
\startcontents[chapters]
\printcontents[chapters]{}{1}{}
\section{Section}
\lipsum[2]
\section{Another section}
\lipsum
\end{document}
但这似乎不太管用。我的实际代码重新定义了\chapter
命令,并将作为章节页面的一部分插入tikzpicture
。我的目标是这样的:
我将非常感激能够指出如何在 TikZ 节点内获取迷你目录,或者如何获取允许我循环访问它们的部分列表,或者以任何其他方式实现我的目标。
答案1
您可以使用minipage
来实现这一点。
下面是一个例子:
\documentclass[oneside]{memoir}
\usepackage{tikz}
\usetikzlibrary{shadows.blur}
\usepackage{titletoc}
\usepackage{lipsum}
\usepackage{calc}
\definecolor{yourcolor}{HTML}{008bb2}
%define new chapter style (just for a nicer look)
\makechapterstyle{mystyle}{%
\chapterstyle{default}
\renewcommand*{\chapnumfont}{\normalfont\Huge\sffamily\bfseries}
\renewcommand*{\chaptitlefont}{\normalfont\huge\sffamily\itshape\color{yourcolor}}
\settowidth{\chapindent}{\chapnumfont 111}
\renewcommand*{\chapterheadstart}{}
\renewcommand*{\chapnamefont}{\hfill\color{yourcolor}\normalfont\Huge\sffamily\bfseries}
\renewcommand*{\printchapternum}{%
\begin{tikzpicture}[baseline={([yshift=-.6ex]current bounding box.center)}]
\node[fill=yourcolor,circle,text=white] {\thechapter};
\end{tikzpicture}\\[1ex]
\hrule height 1.5pt}
\renewcommand*{\printchaptertitle}[1]{%
{\chaptitlefont ##1}}
}
%use new chapter style
\chapterstyle{mystyle}
%command to print the acutal minitoc
\newcommand{\printmyminitoc}{\noindent\hspace{-2cm}\begin{tikzpicture}
\node[rounded corners,align=left,fill=yourcolor, blur shadow={shadow blur steps=5}, inner sep=5mm]{%
\color{white}%
\begin{minipage}{8cm}%minipage trick
\printcontents[chapters]{}{1}{}
\end{minipage}};
\end{tikzpicture}}
\begin{document}
\tableofcontents
\chapter{A chapter}
\startcontents[chapters]
%print minitoc
\printmyminitoc
\section{Section}
\lipsum[1]
\section{Section 2}
\section{test}
\section{abc}
\lipsum
\chapter{Second chapter}
\end{document}
这里是课程的快速演示book
。您可能需要调整页面边框。为了给迷你目录中的页码着色,我使用了https://tex.stackexchange.com/a/186757/10117。
\documentclass[twoside]{book}
\usepackage{tikz}
\usetikzlibrary{shadows.blur}
\usepackage{titletoc}
\usepackage{lipsum}
\usepackage{calc}
\usepackage[]{titlesec}
\definecolor{yourcolor}{HTML}{008bb2}
\colorlet{chpnumbercolor}{black}
\makeatletter
\let\oldl@chapter\l@chapter
\def\l@chapter#1#2{\oldl@chapter{#1}{\textcolor{chpnumbercolor}{#2}}}
\let\old@dottedcontentsline\@dottedtocline
\def\@dottedtocline#1#2#3#4#5{%
\old@dottedcontentsline{#1}{#2}{#3}{#4}{{\textcolor{chpnumbercolor}{#5}}}}
\makeatother
\titleformat{\chapter}[display]
{\normalfont\color{yourcolor}}
{\filleft\Huge\sffamily\bfseries\chaptertitlename\hspace*{2mm}%
\begin{tikzpicture}[baseline={([yshift=-.6ex]current bounding box.center)}]
\node[fill=yourcolor,circle,text=white] {\thechapter};
\end{tikzpicture}}
{1ex}
{\titlerule[1.5pt]\vspace*{5ex}\huge\sffamily\itshape}
[]
\titleformat{name=\chapter,numberless}[display]
{\normalfont\color{yourcolor}}
{}
{1ex}
{\vspace*{5ex}\huge\sffamily\itshape}
[]
%command to print the acutal minitoc
\newcommand{\printmyminitoc}{%
\noindent\hspace{-2cm}%
\colorlet{chpnumbercolor}{white}%
\begin{tikzpicture}
\node[rounded corners,align=left,fill=yourcolor, blur shadow={shadow blur steps=5}, inner sep=5mm]{%
\color{white}%
\begin{minipage}{8cm}%minipage trick
\printcontents[chapters]{}{1}{}
\end{minipage}};
\end{tikzpicture}}
\begin{document}
\tableofcontents
\chapter{A chapter}
\startcontents[chapters]
%print minitoc
\printmyminitoc
\section{Section}
\lipsum[1]
\section{Section 2}
\section{test}
\section{abc}
\lipsum
\chapter{Second chapter}
\end{document}