tikz 和 tableofcontents 之间的冲突

tikz 和 tableofcontents 之间的冲突

为了提交我的论文,我需要使用 Springer 文档类(下面的链接)。事实证明,这会导致 Tikz 和 '\tableofcontents' 之间发生冲突,从而导致编译器不是创建参考书目(去想象)。如果我删除 Tikz 声明和/或目录命令,参考书目运行得很好。我花了一段时间试图理解冲突在哪里,但这超出了我的理解范围。

我将文件精简到最低限度,并添加了一个示例 bib 文件。不幸的是,类文件太长,无法直接发布在这里,但是链接在这里来自 Springer 的网页(只需要 svjour3.cls 和 svglov3.clo 文件)。

主要.tex:

\documentclass[smallextended]{svjour3}
%%% Springer class for Math Z

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\usepackage{tikz}
\usepackage{tikz-cd}
\usetikzlibrary{positioning,arrows,calc}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\usepackage[backend=biber]{biblatex}
\addbibresource{bibliography.bib}

\begin{document}
\title{Bibliography trouble}
\author{GI Joe}

\maketitle

%%%%%%%%%%%%%%%%
\tableofcontents{}
%%%%%%%%%%%%%%%%

\section{One section is enough for trouble}

{\large
The Springer document class creates a clash between Tikz and Table of Contents. \\

No bibliography entry is created for~\cite{A} or~\cite{B}. But if you comment the tikz package declarations (lines 5--7), {\bf OR} if you comment the table of contents command (line 20), the bibliography runs just fine.} \\

\begin{center}{\Large WHY!?}\end{center}

\nocite{*}
\printbibliography

\end{document}

书目.bib:

@article {A,
AUTHOR = {Arthur Ashe},
TITLE = {An able acorn},
JOURNAL = {Antarctica J.},
VOLUME = {1},
YEAR = {1901},
NUMBER = {1},
PAGES = {1--2}
}


@incollection {B,
AUTHOR = "Barry Bonds",
TITLE = "Bibliography blunders",
BOOKTITLE = "Bibliography Book",
PAGES = "1--100",
PUBLISHER = "Basic Books",
YEAR = "1901"
}

答案1

问题是该类尝试在文档末尾写入目录\endgroup

 \AtEndDocument{\addtocontents{toc}{\endgroup}}%

但是 tikz\clearpage首先发出一个,然后写入就永远不会执行。

作为一种解决方法,您可以将其添加到序言中。

\makeatletter
\providecommand*\protected@iwrite[3]{%
  \begingroup
  \let\thepage\relax
  #2%
  \let\protect\@unexpandable@protect
  \edef\reserved@a{\immediate\write#1{#3}}\reserved@a
  \endgroup
  \if@nobreak\ifvmode\nobreak\fi\fi
}
\AtEndDocument{\let\protected@write\protected@iwrite}

\makeatother

\begin{document}

使用当前乳胶的替代方法是重新定义 \tableofcontents 以使用另一个钩子:

\makeatletter
\renewcommand\tableofcontents{%
    \section*{\contentsname}%
    \@starttoc{toc}%
    \addtocontents{toc}{\begingroup\protect\small}%
    \AddToHook{shipout/lastpage}{\addtocontents{toc}{\endgroup}}%
    }

\makeatother

答案2

问题似乎出在 svjour3.cls 中的使用\AtEndDocumet。此代码用于将内容的字体大小设置为小。一种可能的解决方法是注释掉 svjour3.cls 中有问题的行,

1152c1152
<     %\section*{\contentsname}%
---
>     \section*{\contentsname}%
1154,1155c1154,1155
<     %\addtocontents{toc}{\begingroup\protect\small}%
<     %\AtEndDocument{\addtocontents{toc}{\endgroup}}%
---
>     \addtocontents{toc}{\begingroup\protect\small}%
>     \AtEndDocument{\addtocontents{toc}{\endgroup}}%

并设置主文档内容的字体大小:

%%%%%%%%%%%%%%%%
\section*{\contentsname}%
{\small
\tableofcontents{}
}
%%%%%%%%%%%%%%%%

原来的,

在此处输入图片描述

并采用解决方法

在此处输入图片描述

相关内容