装饰作为目录中的条目

装饰作为目录中的条目

我有一本书,里面有许多章节和几个索引。我想在目录中的章节列表和索引列表之间放置一个装饰。我的简单方法失败了(见下文,注释掉第一个示例并取消注释第二个示例)。

有什么方法可以保护 \pgfornament 语句以使其正常工作?

注意:您需要一个 xindy 样式文件才能在编译时显示索引。

% !TEX TS-program = xelatex 
% !TEX encoding = UTF-8
\documentclass[letterpaper,titlepage,twoside,openany,12pt]{book}

%Use Junicode for a nice looking font
\usepackage{xltxtra}
\setmainfont{Junicode}[Language=Icelandic,Fractions=On]

\usepackage[xindy,splitindex]{imakeidx}
\makeindex[title=Index of Tale Information,program=texindy,intoc,columns=2,options=-L icelandic -C utf8 -M lang/icelandic/utf8 -M generalstyle]

\usepackage[object=vectorian]{pgfornament}

\begin{document}
    \tableofcontents
    \mainmatter
    \chapter[Mori]{Móri}
        \index{icelandic!Mori the Hound}
        \index{icelandic titles!Hundurinn Móri}
        \index{collectors!Árnason, Jón}

        \Large Main text

        This is the ornament that I would like in the TOC before the index.

        \pgfornament[width=8cm]{88}

        %Try to add the ornament to the TOC before the index entry
        %It works with simple text
        \addtocontents{toc}{\protect\contentsline{chapter}%
            {\hfill This should be an ornament \hfill}{}}
        %It fails with a tikz object
        %\addtocontents{toc}{\protect\contentsline{chapter}{\pgfornament[width=8cm]{88}}{}}

    \printindex
\end{document}

答案1

这会将装饰物放在\parbox长度为的位置\textwidth,并将其置于中心\centering。您必须\protect同时使用\centering\pgfornament

\addtocontents{toc}{\nobreak\smallskip\parbox{\textwidth}{\protect\centering\protect\pgfornament[width=8cm]{88}}}

这就是结果。

在此处输入图片描述

这是 MWE。

% !TEX TS-program = xelatex 
% !TEX encoding = UTF-8
\documentclass[letterpaper,titlepage,twoside,openany,12pt]{book}

%Use Junicode for a nice looking font
%\usepackage{xltxtra}
%\setmainfont{Junicode}[Language=Icelandic,Fractions=On]

%\usepackage[xindy,splitindex]{imakeidx}
%\makeindex[title=Index of Tale Information,program=texindy,intoc,columns=2,options=-L icelandic -C utf8 -M lang/icelandic/utf8 -M generalstyle]

\usepackage[object=vectorian]{pgfornament}

\begin{document}
    \tableofcontents
    \mainmatter
    \chapter[Mori]{Móri}
%        \index{icelandic!Mori the Hound}
%        \index{icelandic titles!Hundurinn Móri}
%        \index{collectors!Árnason, Jón}

        \addtocontents{toc}{\nobreak\smallskip\parbox{\textwidth}{\protect\centering\protect\pgfornament[width=8cm]{88}}}

\end{document}

答案2

注意:我最初尝试使用 \addtocontents 和 \protect 在原始文档中失败,但在我的 MWE 中成功,原因是由于我使用了 hyperref 包,它重新定义了 \contentsline。

下列工作:

% !TEX TS-program = xelatex 
% !TEX encoding = UTF-8
\documentclass[letterpaper,titlepage,twoside,openany,12pt]{book}

%Use Junicode for a nice looking font
\usepackage{xltxtra}
\setmainfont{Junicode}[Language=Icelandic,Fractions=On]

\usepackage[xindy,splitindex]{imakeidx}
\makeindex[title=Index of Tale Information,program=texindy,intoc,columns=2,options=-L icelandic -C utf8 -M lang/icelandic/utf8 -M generalstyle]

\usepackage[object=vectorian]{pgfornament}

%Provide hyperlinks in the T.O.C. to the chapters
%Note: should be last package loaded
\usepackage[hidelinks]{hyperref}
\hypersetup{pdfpagemode=UseNone}

\begin{document}
    \tableofcontents
    \mainmatter
    \chapter[Mori]{Móri}
        \index{icelandic!Mori the Hound}
        \index{icelandic titles!Hundurinn Móri}
        \index{collectors!Árnason, Jón}

        \Large Main text

        This is the ornament that I would like in the TOC before the index.

        \pgfornament[width=8cm]{88}

        %Try to add the ornament to the TOC before the index entry
        \addtocontents{toc}{\protect\contentsline{chapter}{\hfill%
                \protect\pgfornament[width=8cm]{88}%
                \hfill}{\protect\relax}{}}

    \printindex
\end{document}

相关内容