选自:http://tex.stackexchange.com/questions/51351/modifying-mini-toc-content效果图如下:chapterstyle20130812001221代码如下:

\documentclass[openany]{memoir}

\usepackage{lipsum} % for testing purpose only
\usepackage{mdframed}
\usepackage{mathtools}
\usepackage{hyphenat} % I use it to prevent hyphenation of table of contents items
\usepackage{xcolor}

%%% Do not include titletoc here - do it at the end
%\usepackage{titletoc}

%%% colors definitions
\definecolor{MainRed}{rgb}{.6, .1, .1}
\definecolor{GoldDecoration}{RGB}{170, 120, 70}

% Colored section, subsections, as well as
% chapter and section name in the head - included for completeness
\setsecheadstyle{\color{MainRed}\large\bfseries}
\setsubsecheadstyle{\color{MainRed}\bfseries}
\copypagestyle{myheadings}{headings}
\makeevenhead{myheadings}{\thepage}{}{\color{MainRed}\leftmark}
\makeoddhead{myheadings}{\color{MainRed}\rightmark}{}{\thepage}

%% RedBox style -- adapted from BlueBox style, pp:43-44
% http://mirror.csclub.uwaterloo.ca/CTAN/info/latex-samples/MemoirChapStyles/MemoirChapStyles.pdf
% with modifications from
% http://tex.stackexchange.com/questions/49864/automatically-adjusting-size-of-a-box-based-on-other-content
% and others modifications of my own
\newcommand{\RedBarLength}{3em}

\newsavebox{\ChpNumBox}
\newsavebox{\ChpContBox}
\makeatletter
\newcommand*{\thickhrulefill}{%
\leavevmode\leaders\hrule height 3\p@ \hfill \kern \z@}
\newcommand*\BuildChpNum[3]{%
\begin{tabular}[t]{@{}c@{}}
\makebox[0pt][c]{#1\strut} \\[.5ex]
\colorbox{MainRed}{%
\rule[-\RedBarLength-(#3)]{0pt}{0pt}%
\rule{1ex}{0pt}\color{white}#2\strut
\rule{1ex}{0pt}}%
\end{tabular}}
\makechapterstyle{BoxedChapNum}{%
\renewcommand{\chapnamefont}{\large\scshape}
\setlength{\beforechapskip}{-30pt}
\setlength{\midchapskip}{10pt}
\setlength{\afterchapskip}{30pt}
\renewcommand{\printchaptername}{}
\renewcommand{\chapternamenum}{}
\renewcommand{\printchapternum}{%
\startcontents[chapters]
\sbox{\ChpContBox}{%
\parbox{\linewidth}{%
\printcontents[chapters]{}{1}{\color{blue}}%
}}%
\sbox{\ChpNumBox}{%
\BuildChpNum{\color{GoldDecoration}\bfseries\chapnamefont\@chapapp}%
{\chapnumfont\thechapter}%
{\ht\ChpContBox+\dp\ChpContBox}%
}}
\renewcommand{\printchapternonum}{%
\startcontents[chapters]
\sbox{\ChpContBox}{%
\parbox{\linewidth}{%
%\printcontents[chapters]{}{1}{}% Useless?
}}%
\sbox{\ChpNumBox}{%
\BuildChpNum{\chapnamefont\vphantom{\@chapapp}}%
{\chapnumfont\hphantom{\thechapter}}%
{\ht\ChpContBox+\dp\ChpContBox}%
}}
\renewcommand{\afterchapternum}{}
\renewcommand{\printchaptertitle}[1]{%
\usebox{\ChpNumBox}\hfill
\parbox[t]{\hsize-\wd\ChpNumBox-1em}{%
\raggedright\vspace{\midchapskip}%
{\color{GoldDecoration}\thickhrulefill}\\[10pt]
{\chaptitlefont\LARGE\textcolor{MainRed}{\nohyphens{##1}}}\par\vspace*{10pt}
\renewcommand\cftsectionpagefont{\sffamily\itshape\color{black}}
\renewcommand\cftsubsectionpagefont{\sffamily\itshape\color{black}}
\renewcommand\cftsectionfont{\sffamily\color{MainRed}}
\renewcommand\cftsubsectionfont{\sffamily\color{MainRed}}
\printcontents[chapters]{}{1}{}%
}}%
}
\makeatother

%%%%%% use the newly defined style
\chapterstyle{BoxedChapNum}

%%% Pretty ToC
%%%%% adapted from http://tex.stackexchange.com/questions/35825/pretty-table-of-contents/35835
% a modification of the leftbar environment defined by the framed package
% will be used to place a vertical colored bar separating the page number and the
% title in chapter entries
\renewenvironment{leftbar}{%
\def\FrameCommand{\textcolor{GoldDecoration}{\vrule width 2pt depth 6pt}\hspace*{15pt}}%
\MakeFramed{\advance\hsize-\width\FrameRestore}}%
{\endMakeFramed}

\makeatletter

% redefinitions for chapter entries
\renewcommand\chapternumberline[1]{\mbox{\small\@chapapp~#1}\par\noindent\Large}
\renewcommand\cftchapterfont{\sffamily}
\cftsetindents{chapter}{0pt}{0em}
\renewcommand\cftchapterpagefont{\Huge\sffamily\bfseries\color{MainRed}}

\newcommand*{\l@mychap}[3]{%
\def\@chapapp{\color{MainRed}#3}
\vskip1ex%
\par\noindent\begin{minipage}{\textwidth}%
\parbox{4.5em}{%
\hfill{\cftchapterpagefont#2}%
}\hspace*{1.5em}%
\parbox{\dimexpr\textwidth-4.5em-15pt\relax}{%
\leftbar\cftchapterfont{\color{MainRed}#1}\hspace{1sp}\endleftbar%
}%
\end{minipage}\par%
}
\renewcommand*{\l@chapter}[2]{%
\l@mychap{#1}{#2}{\chaptername}%
}
\renewcommand*{\l@appendix}[2]{%
\l@mychap{#1}{#2}{\appendixname}%
}

% redefinitions for section entries
\renewcommand\cftsectionfont{\sffamily\color{black}}
\renewcommand\cftsectionpagefont{\sffamily\itshape\color{MainRed}}
\renewcommand\cftsectionleader{\nobreak}
\renewcommand\cftsectiondotsep{\cftnodots}
\renewcommand\cftsectionafterpnum{\hspace*{\fill}}
\setlength\cftsectionnumwidth{12em}
\cftsetindents{section}{6em}{3em}
\renewcommand\cftsectionformatpnum[1]{%
\hskip1em\hbox to \@pnumwidth{{\cftsectionpagefont #1\hfill}}}

% redefinitions for subsection entries
\renewcommand\cftsubsectionfont{\sffamily\color{black}}
\renewcommand\cftsubsectionpagefont{\sffamily\itshape\color{MainRed}}
\renewcommand\cftsubsectionleader{\nobreak}
\renewcommand\cftsubsectiondotsep{\cftnodots}
\renewcommand\cftsubsectionafterpnum{\hspace*{\fill}}
\setlength\cftsubsectionnumwidth{12em}
\cftsetindents{subsection}{9em}{3em}
\renewcommand\cftsubsectionformatpnum[1]{%
\hskip1em\hbox to \@pnumwidth{{\cftsubsectionpagefont #1\hfill}}}
\makeatother

%%%% End of Pretty ToC

\settocdepth{subsection}
\setsecnumdepth{subsection}

% include after the change above
\usepackage{titletoc}

\begin{document}
\nouppercaseheads
\pagestyle{myheadings}
\frontmatter
\tableofcontents*
\chapter{Foreword}
\lipsum[9]

\mainmatter
\chapter{First Chapter}
\lipsum[1]
\section{First section}
\lipsum[2]
\subsection{First subsection}
\lipsum[3]
\section{Second section}
\lipsum
\chapter{Second Chapter}
\section{First section}

\appendix
\chapter{First Appendix}
\lipsum[7]
\section{First section}
\lipsum[8]
\section{Second section}
\end{document}

点赞(1)

评论列表 共有 0 条评论

暂无评论
立即
投稿

微信公众账号

微信扫一扫加关注

发表
评论
返回
顶部