让章节缩略图显示在背景框的顶部

让章节缩略图显示在背景框的顶部

在下面给出的代码中,如何让章节缩略图出现在背景框的顶部。

当前代码隐藏了章节拇指框:

在此处输入图片描述

以下是代码:

代码

\documentclass{article}

\RequirePackage{calc}
\RequirePackage[usenames,dvipsnames,svgnames,table]{xcolor}
\RequirePackage{ragged2e}
\RequirePackage{addlines}
\RequirePackage{xparse}
\RequirePackage{etoolbox}
\RequirePackage{varwidth}
\RequirePackage{eso-pic}
\RequirePackage{fancyhdr}
\RequirePackage{marginfix}
\RequirePackage{zref-abspos}
\RequirePackage{titletoc}
\RequirePackage{mdframed}
\RequirePackage{tikz}
\usetikzlibrary{calc}
\usepackage{multicol}
\usepackage{lipsum}

\definecolor{lightGrey}{gray}{0.94}
\definecolor{mainColor}{RGB}{211, 47, 47}
\newcommand\BoxColor{black}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%       Backgrounding commands
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%Vertical lines
\newcommand{\backgroundThisPageGrey}{\bigVerticalLine{bigVerticalLineGrey}}
\newcommand{\backgroundThisPageColor}{\bigVerticalLine{mainColor}}

% Entire page area
\newcounter{background}[page]
\renewcommand{\thebackground}{\arabic{page}-\arabic{background}}

\newcommand{\backgroundAnchor}[1]{\leavevmode\zsavepos{background-#1}}

\newlength{\backgroundInnerTopSpace}
\DeclareDocumentCommand{\startBackground}{O{0mm} O{0mm} O{\thebackground}}{% space_before_begin space_after_begin counter
    \setlength{\backgroundInnerTopSpace}{1em}\addtolength{\backgroundInnerTopSpace}{#2}%
    \vspace*{#1}\newline%
    \backgroundAnchor{begin-#3}\vspace*{\backgroundInnerTopSpace}\\%
}

\DeclareDocumentCommand{\startBackgroundPageTop}{O{\thebackground}}{\begin{tikzpicture}[overlay, remember picture]%
    \node at (current page.north west) {\backgroundAnchor{begin-#1}};
\end{tikzpicture}}

\newlength{\depthLength}
\settodepth{\depthLength}{p}
\newlength{\backgroundInnerBottomSpace}
\newlength{\backgroundOuterBottomSpace}
\DeclareDocumentCommand{\stopBackground}{O{0mm} O{0mm} O{\thebackground}}{% outer_space inner_space counter
    \setlength{\backgroundInnerBottomSpace}{2\depthLength}\addtolength{\backgroundInnerBottomSpace}{#2}%
    \vspace*{\backgroundInnerBottomSpace}%
    \setlength{\backgroundOuterBottomSpace}{1em}\addtolength{\backgroundOuterBottomSpace}{#1}
    \backgroundAnchor{end-#3}\vspace*{\backgroundOuterBottomSpace}
}

\DeclareDocumentCommand{\stopBackgroundPageBottom}{O{\thebackground}}{\tikz[overlay, remember picture]{\node at (current page.south east) {\backgroundAnchor{end-#1}};}}

\tikzset{background/.style = {fill=lightGrey}}
\newcommand{\drawBackground}[1][\thebackground]{%
    \leavevmode%
    \stepcounter{background}%
    \zsavepos{background-draw-#1}%
    \begin{tikzpicture}[remember picture, overlay, inner sep=0mm]
        \fill[background] let
        \p1=(current page.west),
        \p2=(current page.east) in
        (\x1, \zposy{background-begin-#1}sp - \zposy{background-draw-#1}sp) rectangle
        (\x2, \zposy{background-end-#1}sp   - \zposy{background-draw-#1}sp);
    \end{tikzpicture}%
    \ignorespaces
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%       Full width environment
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Saving some length as commands
\newlength{\wholeMargin}
\setlength{\wholeMargin}{\marginparwidth}
\addtolength{\wholeMargin}{\marginparsep}

\newenvironment{whole}{%
    \centering
    \blockmargin
    \begin{adjustwidth*}{0em}{-\wholeMargin}
}{%
    \end{adjustwidth*}
    \unblockmargin
}

\fancypagestyle{ttt}{%

\fancyhf{}%

\fancyhead[RO]{%
            \begin{tikzpicture}[overlay, remember picture]%
            \node[fill=\BoxColor,inner sep=0pt,rectangle,text width=1cm,
                text height=11.7in,align=center,anchor=north east]
                at ($ (current page.north east) + (-0cm,0cm) $)
                {\rotatebox{90}{\parbox{8cm}{%
                \centering\textcolor{white}{\hspace*{5in}\bfseries{\Large Test Of Text Here}}}}};
            \end{tikzpicture}
            }
        \fancyhead[LE]{%
           \begin{tikzpicture}[overlay, remember picture]%
\node[fill=\BoxColor,inner sep=0pt,rectangle,text width=1cm,
    text height=11.7in,align=center,anchor=north east]
  at ($ (current page.north east) + (-0cm,0cm) $)
  {\rotatebox{90}{\parbox{8cm}{%
   \centering\textcolor{white}{\hspace*{5in}\bfseries{\Large Test Of Text Here}}}}};
\end{tikzpicture}
            }
            }

\pagestyle{ttt}

\begin{document}

    \vfill
    \drawBackground\startBackground
    \begin{whole}
        \footnotesize%
        {\color{mainColor}{Example of Table}}
        \begin{multicols}{2}
        \vspace*{0mm}{205 million}\\[1mm]
        \lipsum[1]
        
        \vspace*{3mm}{1\$ million}\\[1mm]
        \lipsum[2]
        
        \columnbreak
        \vspace*{0mm}{136 million}\\[1mm]
        Some words on Facebook in 2016.
        
        \vspace*{3mm}{10 milliom}\\[1mm]
        \lipsum[3]
        
        \vspace*{3mm}{527 billion}\\[1mm]
        \lipsum[4]
        \end{multicols}
    \end{whole}
    \stopBackgroundPageBottom


\end{document}

答案1

将背景放在脚部而不是头部。脚部是在文本主体之后创建的,因此它将覆盖文本:

\fancyfoot[RO]{%<----foot
            \begin{tikzpicture}[overlay, remember picture]%
            \node[fill=\BoxColor,inner sep=0pt,rectangle,text width=1cm,
                text height=11.7in,align=center,anchor=north east]
                at ($ (current page.north east) + (-0cm,0cm) $)
                {\rotatebox{90}{\parbox{8cm}{%
                \centering\textcolor{white}{\hspace*{5in}\bfseries{\Large Test Of Text Here}}}}};
            \end{tikzpicture}
            }

使用新的 latex,您还可以将代码放入新的 shipout/foreground 钩子中。或者您可以使用 eso-pic,它也有用于前台的代码。

在此处输入图片描述

相关内容