在双页布局中获取正确位于页面外边缘的渐变外页边缘

在双页布局中获取正确位于页面外边缘的渐变外页边缘
\newcommand{\gradientbox}[3]{% define func to create the gradientbox for the edge
    \begin{tikzpicture}
        \node[left color=#1,right color=#2] {#3};
    \end{tikzpicture}%
    }

\AddToShipoutPicture{%
    \AtPageLowerLeft{%
        \rotatebox{90}{
            \gradientbox{lightGreen}{darkGreen}{% call gradient func
                \begin{minipage}{\paperheight}%
                    \hspace*{ \stretch{1} }{\bfseries\large\textcolor{white}{Book I - Player Information}}\hspace*{\stretch{1}}
                \end{minipage}%
                }% end content of the edge gradient
            }% end rotate
        }% end at page lowerleft
    }% end edge placement

所以,这是我正在使用的代码。我再也找不到原始来源了(几个月前我第一次开始使用 LaTeX 时找到了它,现在我带着轻微地更好地理解整个过程。无论如何,我试图实现的是这种效果,但根据页面是奇数还是偶数来交替哪一侧。

我尝试了几种不同的选项,例如 if\then,但它们并没有像我预期的那样工作。我最终相当肯定,我从根本上误解了上述代码的结构,如果我有更好的理解,我之前的尝试可能会奏效。无论如何,我将不胜感激您的帮助(以及任何见解)。可能值得一提的是,我试图在标题中声明这一点,并尽可能少地触及实际文本,因为这看起来像是糟糕的设计(但我来自 HTML 背景,所以也许我错了)。

哦,这是我的包含块:

\documentclass[12pt,twoside,letterpaper,titlepage,twocolumn]{book}
\usepackage{xcolor}     % package to use defined colors
\usepackage{tikz}       % package to create figures procedurally
\usepackage{eso-pic}    % package to manipulate images, either by tikz or standard
\usepackage{fontspec}   % package to manipulate fonts
\usepackage{fancyhdr}   % package to create custom headers and footers
\usepackage{ifthen}     % package to handle logical statements for layout
\usepackage{titlesec}   % package to handle beautifying headings
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
\usepackage{geometry}   % package to handle margins, ect

编辑:这是在奇数页上的样子(是正确的)。

代码运行正确,在奇数页上正确

答案1

这会将同一个框交替放置在左侧和右侧。请注意,渐变也会旋转。 \AddToHook相对较新,并内置于 LaTeX 中。

由于 darkGreen 和 lightGreen 颜色未定义,因此我使用了 svgnames DarkGreen 和 LightGreen。我禁用了 fontspec,这样就不必使用 XeLaTeX(速度很慢)。

\documentclass[12pt,twoside,letterpaper,titlepage,twocolumn]{book}
\usepackage[svgnames]{xcolor}     % package to use defined colors
\usepackage{tikz}       % package to create figures procedurally
%\usepackage{eso-pic}    % package to manipulate images, either by tikz or standard
%\usepackage{fontspec}   % package to manipulate fonts
\usepackage{fancyhdr}   % package to create custom headers and footers
\usepackage{ifthen}     % package to handle logical statements for layout
\usepackage{titlesec}   % package to handle beautifying headings
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
\usepackage{geometry}   % package to handle margins, ect

\newcommand{\gradientbox}[3]{% define func to create the gradientbox for the edge
    \begin{tikzpicture}
        \node[left color=#1,right color=#2,inner sep=0.333em] {#3};
    \end{tikzpicture}%
}

\newsavebox{\marginbox}
\savebox{\marginbox}{\gradientbox{LightGreen}{DarkGreen}{% call gradient func
   \makebox[\dimexpr \paperheight-0.666em]%
     {\bfseries\large\textcolor{white}{Book I - Player Information}}%
}}
    
\AddToHook{shipout/background}{\ifodd\value{page}\relax
  \put ({\dimexpr \paperwidth-\ht\marginbox},0pt) {\rotatebox{-90}{\usebox\marginbox}}%
\else
  \put (0pt,-\paperheight) {\rotatebox{90}{\usebox\marginbox}}%
\fi}
  
\usepackage{lipsum}% MWE only

\begin{document}
\lipsum[1-12]
\end{document}

此版本使用 everypage 包。

\documentclass[12pt,twoside,letterpaper,titlepage,twocolumn]{book}
\usepackage[svgnames]{xcolor}     % package to use defined colors
\usepackage{tikz}       % package to create figures procedurally
%\usepackage{eso-pic}    % package to manipulate images, either by tikz or standard
%\usepackage{fontspec}   % package to manipulate fonts
\usepackage{fancyhdr}   % package to create custom headers and footers
\usepackage{ifthen}     % package to handle logical statements for layout
\usepackage{titlesec}   % package to handle beautifying headings
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
\usepackage{geometry}   % package to handle margins, ect
\usepackage{everypage}

\newcommand{\gradientbox}[3]{% define func to create the gradientbox for the edge
    \begin{tikzpicture}
        \node[left color=#1,right color=#2,inner sep=0.333em] {#3};
    \end{tikzpicture}%
}

\newsavebox{\marginbox}
\savebox{\marginbox}{\gradientbox{LightGreen}{DarkGreen}{% call gradient func
   \makebox[\dimexpr \paperheight-0.666em]%
     {\bfseries\large\textcolor{white}{Book I - Player Information}}%
}}
    
\AddEverypageHook{\ifodd\value{page}\relax
  \rlap{\hspace{\dimexpr \paperwidth-\ht\marginbox-1in}%
    \raisebox{1in}[0pt][0pt]{\rotatebox{-90}{\usebox\marginbox}}}%
\else
  \rlap{\hspace{-1in}\raisebox{\dimexpr 1in-\paperheight}[0pt][0pt]{\rotatebox{90}{\usebox\marginbox}}}%
\fi}
  
\usepackage{lipsum}% MWE only

\begin{document}
\lipsum[1-12]
\end{document}

相关内容