TOC 長度超過 1 頁會導致 Tikz 在後續頁面上的絕對定位混亂

TOC 長度超過 1 頁會導致 Tikz 在後續頁面上的絕對定位混亂

我遇到一個問題,目錄位於多個頁面上,會破壞 pdf 其餘部分的 tikz 定位。例子:

在此輸入影像描述

標題已移至頁面底部,而它通常位於頁面頂部。

現在看程式碼:將標題載入到頁面中,如下所示:

\begin{document}

    \input{graphics/pagestyle/titlepage.tex}
    \pagecolor{none}
    \newpage

    \AddToShipoutPicture{\BackgroundPic}

    \tableofcontents

\BackgroundPic 定義如下:

\usepackage{kpfonts}
\usepackage[explicit]{titlesec}
\newcommand*\headerbg{
  {\begin{tikzpicture}[remember picture,overlay]
    \node[yshift=-3cm] at (current page.north west)
      {\begin{tikzpicture}[remember picture, overlay]
        \draw[fill=WLEBlue1] (0,0) rectangle
          (\paperwidth,3cm);
          \node (label) at (10,1.5){
            \includegraphics[width=660pt]{graphics/pagestyle/header_bg.png}
          };
          \node (label) at (1.4,1.5){
            \includegraphics[width=60pt]{graphics/pagestyle/WLE_Logo.png}
          };
       \end{tikzpicture}
      };
   \end{tikzpicture}
  }
  }

\usepackage{eso-pic}
\newcommand\BackgroundPic{
\headerbg
\put(0,0){
\parbox[b][\paperheight]{\paperwidth}{%
\vfill
\centering
\begin{tikzpicture}[remember picture,overlay]
    \node at (-10,12.5)
      {\begin{tikzpicture}[remember picture, overlay]
            \draw [WLEBlue1, fill=WLEBlue1] (0,0) -- (0.05,0) -- (0.05,-22.2) -- (0.25,-22.2) -- (0.25, -23) -- (0, -23);
       \end{tikzpicture}
      };
\end{tikzpicture}
\begin{tikzpicture}[remember picture,overlay]
\node at (8.5,12.5)
      {\begin{tikzpicture}[remember picture, overlay]
            \draw [WLEBlue1, fill=WLEBlue1] (-1, -23) -- (0, -23) -- (0, -22) -- (-0.08, -22) -- (-0.08, -22.92) -- (-1, -22.92);
       \end{tikzpicture}
      };
\end{tikzpicture}
\vfill
}}}
        \newpage

當目錄只有 1 頁長時,它運作得很好,當目錄達到 2 頁時,它就會出錯。任何幫助是極大的讚賞!先感謝您。

更新:不久前將此作為評論發布,但決定將其移至此處以提高可見度:這裡ShareLatex 的線上版本顯示了這個問題。您可以在那裡查看並編輯一些範例程式碼並自行編譯。

更新:嘗試刪除 TikzPictures 的嵌套,但沒有幫助。沒有嵌套圖片的程式碼:

\newcommand*\headerbg{
    \begin{tikzpicture}[overlay]
        \node(base) at (current page.north west) {};
        \node at ($(base)+(9.1,0.7)$){
            \includegraphics[width=660pt]{header_bg.png}
        };
        \node at ($(base)+(0.5,0.7)$){
            \includegraphics[width=60pt]{WLE_Logo.png}
        };
    \end{tikzpicture}
}

更新:導致問題的是章節樣式,刪除章節樣式也可以解決這個問題。

\newcommand*\chapterlabel{}
\titleformat{\chapter}
  {\gdef\chapterlabel{}
   \normalfont\sffamily\Huge\bfseries\scshape}
  {\gdef\chapterlabel{\thechapter\ }}{0pt}
  {\begin{tikzpicture}[remember picture,overlay]
    \node at (0,0)
      {\begin{tikzpicture}[remember picture, overlay]
        \draw[WLEBlue2, fill=WLEBlue2] (0,0) rectangle
          (\textwidth,1cm);
        \node[
            inner xsep=1ex,
            text width=\linewidth-2*\pgfkeysvalueof{/pgf/inner xsep},
            align=left] at (9,0.5)
              {\color{white}\chapterlabel#1};
       \end{tikzpicture}
      };
   \end{tikzpicture}
  }

答案1

已修復,問題出在章節樣式。我刪除了記住圖片tikzpictures 上的選項似乎已經解決了這個問題。我不完全確定為什麼記住圖片選項會導致此問題。

\newcommand*\chapterlabel{}
\titleformat{\chapter}
  {\gdef\chapterlabel{}
   \normalfont\sffamily\Huge\bfseries\scshape}
  {\gdef\chapterlabel{\thechapter\ }}{0pt}
  {\begin{tikzpicture}[overlay]
    \node at (0,0)
      {\begin{tikzpicture}[overlay]
        \draw[WLEBlue2, fill=WLEBlue2] (0,0) rectangle
          (\textwidth,1cm);
        \node[
            inner xsep=1ex,
            text width=\linewidth-2*\pgfkeysvalueof{/pgf/inner xsep},
            align=left] at (9,0.5)
              {\color{white}\chapterlabel#1};
       \end{tikzpicture}
      };
   \end{tikzpicture}
  }

相關內容