我想为每一页应用不同的标题/边框。页脚将全部相同。我希望它看起来像这样:
我可以让前两页有所不同,但我不知道如何让后续页面有所不同。
前两页的代码:
\documentclass[11pt]{article}
\usepackage[hmargin=1cm,bmargin=2cm,tmargin=2cm,centering]{geometry}
\usepackage{graphicx}
\usepackage{amssymb}
\usepackage[rgb]{xcolor}
\usepackage{framed}
\usepackage{multicol}
\usepackage{lipsum}
\usepackage[none]{hyphenat}
\usepackage{parskip}
\definecolor{boxgray}{rgb}{.55,.54,.54}
\definecolor{bluey}{RGB}{0,121,194} %Alcon color
\definecolor{card}{RGB}{133,23,24}
\usepackage{tikz}
\usepackage{tikzpagenodes}
\usepackage{atbegshi}
\newcommand\Header{%
\begin{tikzpicture}[remember picture,overlay]
\path [fill=boxgray]
([xshift=1cm]current page.north west) -- ([xshift=7cm]current page.north west) -- ([xshift=7cm]current page.south west) -- ([xshift=1cm]current page.south west) -- cycle;
\path [fill=card]
(current page.north west) -- (current page.north east) --
([yshift=-1.5cm]current page.north east|-current page text area.north east) .. controls (10,0.25) ..
([yshift=-2.5cm]current page.north west|-current page text area.north west) -- cycle;
\node[font=\bfseries\color{white},anchor=east,
xshift=-1.5cm,yshift=-1.3cm] at (current page.north east)
{\fontsize{40}{60}\selectfont Newsletter};
\end{tikzpicture}%
}
\newcommand\Footer{%
\begin{tikzpicture}[remember picture,overlay]
\fill[bluey]
(current page.south west) -- (current page.south east) --
([yshift=-25pt]current page.south east|-current page text area.south east) --
([yshift=-25pt]current page.south west|-current page text area.south west) -- cycle;
\node[yshift=0.5cm,font=\bfseries\color{white}] at (current page.south) {\fontsize{15}{24}\selectfont};;
\end{tikzpicture}%
}
\newcommand\HeaderTwo{%
\begin{tikzpicture}[remember picture,overlay]
\fill[card]
(current page.north west) -- (current page.north east) --
([yshift=10pt]current page.north east|-current page text area.north east) --
([yshift=10pt]current page.north west|-current page text area.north west) -- cycle;
\node[font=\bfseries\color{white},anchor=east,
xshift=-.5cm,yshift=-1cm] at (current page.north east)
{\fontsize{20}{60}\selectfont Text};
\end{tikzpicture}%
}
\pagestyle{empty}
\AtBeginShipout{\HeaderTwo\Footer}
\AtBeginShipoutFirst{\Header\Footer}
\begin{document}
\vspace*{2.cm}
%Page1leftbox
\begin{minipage}[t]{60mm}
\centering
\begin{minipage}[t]{.95\linewidth}
Text...
\end{minipage}
\end{minipage}\hfill
%Page1main
\begin{minipage}[t]{.675\linewidth}
\begin{center}
\textbf{\Large Header1}
\end{center}
\parskip = 5pt
\lipsum[1-4]
\end{minipage}
\clearpage
%Page2main
\lipsum
\end{document}
以及第 3 页边框的代码:
\documentclass{article}
\usepackage[hmargin=1cm,bmargin=2cm,tmargin=2cm,centering]{geometry}
\usepackage{tikzpagenodes}
%\usetikzlibrary{calc}
\usepackage{lmodern}
\usepackage{multicol}
\usepackage{lipsum}
\usepackage{atbegshi}
\definecolor{boxgray}{rgb}{.55,.54,.54}
\definecolor{card}{RGB}{133,23,24}
\definecolor{bluey}{RGB}{0,121,194}
\newcommand\Header{%
\begin{tikzpicture}[remember picture,overlay]
\fill[card]
(current page.north west) -- (current page.north east) --
([yshift=-300pt]current page.north east|-current page text area.north east) -- %right
([yshift=0pt,xshift=100pt]current page.north|-current page text area.north) -- %mid
([yshift=0pt]current page.north west|-current page text area.north west) -- cycle; %left
\node[rotate=-57,font=\sffamily\bfseries\color{boxgray},anchor=east,
xshift=8cm,yshift=-6cm] at (current page.north east)
{\fontsize{40}{60}\selectfont Newsletter Test};
\fill[boxgray]
(current page.south west) -- (current page.south east) --
([yshift=-300pt]current page.north east|-current page text area.north east) -- %right
([yshift=-30pt,xshift=100pt]current page.south|-current page text area.south) --
([yshift=0pt]current page.south west|-current page text area.south west) -- cycle;
\end{tikzpicture}%
}
\newcommand\Footer{%
\begin{tikzpicture}[remember picture,overlay]
\fill[bluey]
(current page.south west) -- (current page.south east) --
([yshift=-25pt]current page.south east|-current page text area.south east) --
([yshift=-25pt]current page.south west|-current page text area.south west) -- cycle;
\end{tikzpicture}%
}
\pagestyle{empty}
\AtBeginShipoutFirst{\Header\Footer}
\begin{document}
\begin{minipage}[t]{.65\linewidth}
\vspace{10pt}
\begin{multicols}{2}
\lipsum[1-6]
\end{multicols}
\end{minipage}
\end{document}
- 我怎样才能将它们全部合并到一个文档中,并可能包含具有不同设计的更多页面?
- 此代码似乎在文档末尾生成了一个空白页。为什么?我该如何停止这种情况?
答案1
一种可能性是使用background
包裹:
\documentclass{article}
\usepackage[a6paper]{geometry}% just for the example
\usepackage{ifthen}
\usepackage[
scale=1,
opacity=1,
angle=0
]{background}
% command for modular arithmetic
\def\truncdiv#1#2{((#1-(#2-1)/2)/#2)}
\def\moduloop#1#2{(#1-\truncdiv{#1}{#2}*#2)}
\def\modulo#1#2{\number\numexpr\moduloop{#1}{#2}\relax}
% definitions of colors to be used
\definecolor{color1}{RGB}{11,64,176}% blue
\definecolor{color2}{RGB}{133,23,24}% red
\definecolor{color3}{RGB}{107,107,107}% red
% command for the footer
\newcommand\Footer{%
\begin{tikzpicture}[remember picture,overlay]
\fill[color1]
([yshift=20pt]current page.south west)
rectangle
(current page.south east);
\end{tikzpicture}%
}
% header for pages congrunent with 3 modulo 0
\newcommand\Headerz{%
\begin{tikzpicture}[remember picture,overlay]
\fill[color2]
(current page.north west) --
(current page.north east) --
(current page.east) --
([xshift=-50pt,yshift=-25pt]current page.north east) --
([yshift=-25pt]current page.north west) --
cycle;
\fill[color3]
(current page.east) --
([xshift=-50pt,yshift=20pt]current page.south east) --
([yshift=20pt]current page.south east) --
cycle;
\end{tikzpicture}%
}
% header for pages congrunent with 3 modulo 1
\newcommand\Headero{%
\begin{tikzpicture}[remember picture,overlay]
\fill[color2]
(current page.north west) --
(current page.north east) --
([yshift=-70pt]current page.north east)
to[out=160,in=20]
([yshift=-70pt]current page.north west) --
cycle;
\end{tikzpicture}%
}
% header for pages congrunent with 3 modulo 2
\newcommand\Headert{%
\begin{tikzpicture}[remember picture,overlay]
\fill[color2]
(current page.north west)
rectangle
([yshift=-25pt]current page.north east);
\end{tikzpicture}%
}
% include common footer
\backgroundsetup{contents=\Footer}
% add header depending on the value of the page modulo 3
\AddEverypageHook{%
\ifthenelse{\modulo{\value{page}}{3}=0}
{\backgroundsetup{contents={\Headerz}}}
{%
\ifthenelse{\modulo{\value{page}}{3}=1}
{\backgroundsetup{contents={\Headero}}}
{%
\ifthenelse{\modulo{\value{page}}{3}=2}
{\backgroundsetup{contents={\Headert}}}
{}
}%
}
\BgMaterial
}
\begin{document}
text\clearpage
text\clearpage
text\clearpage
text\clearpage
text\clearpage
text\clearpage
text\clearpage
text\clearpage
text\clearpage
text\clearpage
text\clearpage
text
\end{document}
这个想法是为标题定义尽可能多的不同装饰,然后根据页面计数器的模块化算法有条件地包含它们;示意图
if the residue of the page number modulo 3 is zero
use \Headerz as background
else if the residue of the page number modulo 3 is one
use \Headero as background
else if the residue of the page number modulo 3 is two
use \Headert as background
fififi
显然,这很容易推广到任意数量的不同标题。
这是使用问题代码中的修饰的版本:
\documentclass{article}
\usepackage[
hmargin=1cm,
bmargin=2cm,
tmargin=2cm,
centering
]{geometry}
\usepackage{ifthen}
\usepackage{tikzpagenodes}
\usepackage[
scale=1,
opacity=1,
angle=0,
contents={}
]{background}
% command for modular arithmetic
\def\truncdiv#1#2{((#1-(#2-1)/2)/#2)}
\def\moduloop#1#2{(#1-\truncdiv{#1}{#2}*#2)}
\def\modulo#1#2{\number\numexpr\moduloop{#1}{#2}\relax}
% definitions of colors to be used
\definecolor{boxgray}{rgb}{.55,.54,.54}
\definecolor{bluey}{RGB}{0,121,194} %Alcon color
\definecolor{card}{RGB}{133,23,24}
% command for the footer
\newcommand\Footer{%
\begin{tikzpicture}[remember picture,overlay]
\fill[bluey]
(current page.south west) -- (current page.south east) --
([yshift=-25pt]current page.south east|-current page text area.south east) --
([yshift=-25pt]current page.south west|-current page text area.south west) -- cycle;
\node[yshift=0.5cm,font=\bfseries\color{white}] at (current page.south) {\fontsize{15}{24}\selectfont};;
\end{tikzpicture}%
}
% header for pages congrunent with 3 modulo 0
\newcommand\Headerz{%
\begin{tikzpicture}[remember picture,overlay]
\path [fill=boxgray]
([xshift=1cm]current page.north west) -- ([xshift=7cm]current page.north west) -- ([xshift=7cm]current page.south west) -- ([xshift=1cm]current page.south west) -- cycle;
\path [fill=card]
(current page.north west) -- (current page.north east) --
([yshift=-1.5cm]current page.north east|-current page text area.north east) .. controls (10,0.25) ..
([yshift=-2.5cm]current page.north west|-current page text area.north west) -- cycle;
\node[font=\bfseries\color{white},anchor=east,
xshift=-1.5cm,yshift=-1.3cm] at (current page.north east)
{\fontsize{40}{60}\selectfont Newsletter};
\end{tikzpicture}%
}
% header for pages congrunent with 3 modulo 1
\newcommand\Headero{%
\begin{tikzpicture}[remember picture,overlay]
\fill[card]
(current page.north west) -- (current page.north east) --
([yshift=10pt]current page.north east|-current page text area.north east) --
([yshift=10pt]current page.north west|-current page text area.north west) -- cycle;
\node[font=\bfseries\color{white},anchor=east,
xshift=-.5cm,yshift=-1cm] at (current page.north east)
{\fontsize{20}{60}\selectfont Text};
\end{tikzpicture}%
}
% header for pages congrunent with 3 modulo 2
\newcommand\Headert{%
\begin{tikzpicture}[remember picture,overlay]
\fill[card]
(current page.north west) -- (current page.north east) --
([yshift=-300pt]current page.north east|-current page text area.north east) -- %right
([yshift=0pt,xshift=100pt]current page.north|-current page text area.north) -- %mid
([yshift=0pt]current page.north west|-current page text area.north west) -- cycle; %left
\node[rotate=-57,font=\sffamily\bfseries\color{boxgray},anchor=east,
xshift=8cm,yshift=-6cm] at (current page.north east)
{\fontsize{40}{60}\selectfont Newsletter Test};
\fill[boxgray]
(current page.south west) -- (current page.south east) --
([yshift=-300pt]current page.north east|-current page text area.north east) -- %right
([yshift=-30pt,xshift=100pt]current page.south|-current page text area.south) --
([yshift=0pt]current page.south west|-current page text area.south west) -- cycle;
\end{tikzpicture}%
}
% add header depending on the value of the page modulo 3
\AddEverypageHook{%
\ifthenelse{\modulo{\value{page}}{3}=0}
{\backgroundsetup{contents={\Headerz}}}
{%
\ifthenelse{\modulo{\value{page}}{3}=1}
{\backgroundsetup{contents={\Headero}}}
{%
\ifthenelse{\modulo{\value{page}}{3}=2}
{\backgroundsetup{contents={\Headert}}}
{}
}%
}
\BgMaterial
}
% add footer
\AddEverypageHook{%
\backgroundsetup{contents={\Footer}}
\BgMaterial
}
\pagestyle{empty}
\begin{document}
text\clearpage
text\clearpage
text\clearpage
text\clearpage
text\clearpage
text\clearpage
text\clearpage
text\clearpage
text\clearpage
text\clearpage
text\clearpage
text
\end{document}
为了进行条件测试,我借用了\modulo
由以下定义的宏埃格尔在his answer
到
如何在 LaTeX 中计算 n 模 3?。
如果背景不应该在页面之间循环,但每个页面都必须有自己的装饰,则需要定义与文档中的页面一样多的装饰,然后代码就会简化,因为取决于计数器值的简单条件测试page
会决定背景:一个具有四个背景的简单示例(我\HeadeFour
为第四页设计了一个快速装饰):
\documentclass{article}
\usepackage[
hmargin=1cm,
bmargin=2cm,
tmargin=2cm,
centering
]{geometry}
\usepackage{tikzpagenodes}
\usepackage[
scale=1,
opacity=1,
angle=0,
contents={}
]{background}
% definitions of colors to be used
\definecolor{boxgray}{rgb}{.55,.54,.54}
\definecolor{bluey}{RGB}{0,121,194} %Alcon color
\definecolor{card}{RGB}{133,23,24}
% command for the footer
\newcommand\Footer{%
\begin{tikzpicture}[remember picture,overlay]
\fill[bluey]
(current page.south west) -- (current page.south east) --
([yshift=-25pt]current page.south east|-current page text area.south east) --
([yshift=-25pt]current page.south west|-current page text area.south west) -- cycle;
\node[yshift=0.5cm,font=\bfseries\color{white}] at (current page.south) {\fontsize{15}{24}\selectfont};;
\end{tikzpicture}%
}
% header for page one
\newcommand\HeaderOne{%
\begin{tikzpicture}[remember picture,overlay]
\path[fill=boxgray]
([xshift=1cm]current page.north west) -- ([xshift=7cm]current page.north west) -- ([xshift=7cm]current page.south west) -- ([xshift=1cm]current page.south west) -- cycle;
\path [fill=card]
(current page.north west) -- (current page.north east) --
([yshift=-1.5cm]current page.north east|-current page text area.north east) .. controls (10,0.25) ..
([yshift=-2.5cm]current page.north west|-current page text area.north west) -- cycle;
\node[font=\bfseries\color{white},anchor=east,
xshift=-1.5cm,yshift=-1.3cm] at (current page.north east)
{\fontsize{40}{60}\selectfont Newsletter};
\end{tikzpicture}%
}
% header for page two
\newcommand\HeaderTwo{%
\begin{tikzpicture}[remember picture,overlay]
\fill[card]
(current page.north west) -- (current page.north east) --
([yshift=10pt]current page.north east|-current page text area.north east) --
([yshift=10pt]current page.north west|-current page text area.north west) -- cycle;
\node[font=\bfseries\color{white},anchor=east,
xshift=-.5cm,yshift=-1cm] at (current page.north east)
{\fontsize{20}{60}\selectfont Text};
\end{tikzpicture}%
}
% header for page three
\newcommand\HeaderThree{%
\begin{tikzpicture}[remember picture,overlay]
\fill[card]
(current page.north west) -- (current page.north east) --
([yshift=-300pt]current page.north east|-current page text area.north east) -- %right
([yshift=0pt,xshift=100pt]current page.north|-current page text area.north) -- %mid
([yshift=0pt]current page.north west|-current page text area.north west) -- cycle; %left
\node[rotate=-57,font=\sffamily\bfseries\color{boxgray},anchor=east,
xshift=8cm,yshift=-6cm] at (current page.north east)
{\fontsize{40}{60}\selectfont Newsletter Test};
\fill[boxgray]
(current page.south west) -- (current page.south east) --
([yshift=-300pt]current page.north east|-current page text area.north east) -- %right
([yshift=-30pt,xshift=100pt]current page.south|-current page text area.south) --
([yshift=0pt]current page.south west|-current page text area.south west) -- cycle;
\end{tikzpicture}%
}
% header for page four
\newcommand\HeaderFour{%
\begin{tikzpicture}[remember picture,overlay]
\fill[boxgray]
([xshift=-1cm]current page.north east) -- ([xshift=-4cm]current page.north east) -- ([xshift=-4cm]current page.south east) -- ([xshift=-1cm]current page.south east) -- cycle;
\fill[card]
(current page.north west) --
(current page.north east) --
([yshift=-40pt]current page.north east|-current page text area.north east)
to[out=160,in=20]
([yshift=-40pt]current page.north west|-current page text area.north west) -- cycle;
\node[font=\bfseries\color{white},anchor=east,
xshift=-.5cm,yshift=-1cm] at (current page.north east)
{\fontsize{20}{60}\selectfont Text};
\end{tikzpicture}%
}
% add header depending on the value of the page modulo 3
\AddEverypageHook{%
\ifnum\value{page}=1\relax
\backgroundsetup{contents={\HeaderOne}}
\else
\ifnum\value{page}=2\relax
\backgroundsetup{contents={\HeaderTwo}}
\else
\ifnum\value{page}=3\relax
\backgroundsetup{contents={\HeaderThree}}
\else
\ifnum\value{page}=4\relax
\backgroundsetup{contents={\HeaderFour}}
\fi\fi\fi\fi
\BgMaterial
}
\AddEverypageHook{%
\backgroundsetup{contents=\Footer}
\BgMaterial
}
\pagestyle{empty}
\begin{document}
text\clearpage
text\clearpage
text\clearpage
text
\end{document}
我的示例中的命令\clearpage
只是为了简洁起见(快速生成几页);在具有真实内容的真实文档中并不真正需要它们。