如何在附录中添加章节标题格式?

如何在附录中添加章节标题格式?

平均能量损失

\documentclass{book}
\usepackage[explicit]{titlesec}
\usepackage{makeidx}
\makeindex
\usepackage{tikz}

\newcommand{\chaptercolor}{blue}
\titleformat{\chapter}
[display]
{\normalfont\filcenter}
{\tikz[remember picture,overlay]
{\node[fill=\chaptercolor,%<--- Not hardcoded color
   font=\sffamily\fontsize{96}{72}\bf\selectfont\color{white},anchor=north east, 
   minimum width=3cm, 
   minimum height=3.4cm] 
   at ([xshift=-1cm,yshift=-1cm]current page.north east) 
     (numb) {\thechapter};
 \node[rotate=90,
       anchor=south,
       inner sep=4pt,
       font=\Huge\itshape]
   at (numb.west) {\chaptertitlename};%<-- Not hardcoded "CHAPTER"
}}
{20pt}
{\raggedright\Huge\bfseries\itshape\color{\chaptercolor}#1}%< Not hardcoded color
[\vskip10pt\Large\bfseries]

\begin{document}

\chapter{Preface}
\index{one}\index{two}\index{ten}
\appendix

\chapter*{Index}
\printindex
\end{document}

输出

在此处输入图片描述

我尝试的输出如下。但我做不到。我的代码会有什么变化?

在此处输入图片描述

编辑: @Sveinung 在我的电脑上输出

在此处输入图片描述

答案1

使用imakeidx包,然后从这里很好的答案,我找到了以下解决方案。

\documentclass[]{book}
\usepackage{xpatch}
\usepackage[explicit]{titlesec}
%%%%%%%%% New code block %%%%%%%%
\usepackage{imakeidx}
\indexsetup{level=\chapter} 
\makeindex[columns=1]
\makeatletter
\xpatchcmd{\imki@putindex}
{\immediate}
{\ifimki@disableautomatic\else\immediate}
{}{}
\xpatchcmd{\imki@putindex}
{\endcsname}
{\endcsname\fi}
{}{}
\makeatother
%%%%%%%%% End of New code block %%%%%%%%

\usepackage{tikz}
\newcommand{\chaptercolor}{blue}
\titleformat{\chapter}
[display]
{\normalfont\filcenter}
{\tikz[remember picture,overlay]
{\node[fill=\chaptercolor,%<--- Not hardcoded color
   font=\sffamily\fontsize{96}{72}\bf\selectfont\color{white},anchor=north east, 
   minimum width=3cm, 
   minimum height=3.4cm] 
   at ([xshift=-1cm,yshift=-1cm]current page.north east) 
     (numb) {\thechapter};
 \node[rotate=90,
       anchor=south,
       inner sep=4pt,
       font=\Huge\itshape]
   at (numb.west) {\chaptertitlename};%<-- Not hardcoded "CHAPTER"
}}
{20pt}
{\raggedright\Huge\bfseries\itshape\color{\chaptercolor}#1}%< Not hardcoded color
[\vskip10pt\Large\bfseries]



\begin{document}
\chapter{Preface}
\index{one}\index{two}\index{ten}
\appendix

%\chapter{Index} %<-- No need 
\printindex
\chapter{Foo}
\end{document}

在此处输入图片描述

相关内容