我想创建一个模板,如下所示。但我希望它能使我拥有多个相同布局的页面,并且每次都能轻松地用不同的单词替换“标题 1”和“标题 2”。
我可以使用下面的代码制作灰色框并放置文字。现在我将它们作为标题,以便可以轻松地将其放置在每个页面上。
\begin{tikzpicture}[remember picture,overlay, fill]
\path [fill=lightgray]
([yshift=9cm]current page.west) -- ([yshift=9cm,xshift=12cm]current page.west) -- ([yshift=8.5cm,xshift=12cm]current page.west) -- ([yshift=8.5cm]current page.west) -- cycle;
\path [fill=lightgray]
([yshift=0cm]current page.west) -- ([yshift=0cm,xshift=12cm]current page.west) -- ([yshift=-0.5cm,xshift=12cm]current page.west) -- ([yshift=-0.5cm]current page.west) -- cycle;
\node[font=\bfseries\color{black},anchor=west,
xshift=1cm,yshift=9.5cm] at (current page.west)
{\fontsize{40}{60}\selectfont Header 1};
\node[font=\bfseries\color{black},anchor=west,
xshift=1cm,yshift=0.5cm] at (current page.west)
{\fontsize{40}{60}\selectfont Header 2};
\end{tikzpicture}%
但我想知道是否有办法用 tikz 图片定义一个新环境,这样我就可以定义该环境并根据需要更改单词,而不必每次单独放置标题/单词。
答案1
如果你不想在 tikzpicture 环境中使用任何其他东西,那么你可以定义
\newcommand\PageHeader[2]{%
\begin{tikzpicture}[remember picture,overlay, fill]
\path [fill=lightgray]
([yshift=9cm]current page.west) -- ([yshift=9cm,xshift=12cm]current page.west) -- ([yshift=8.5cm,xshift=12cm]current page.west) -- ([yshift=8.5cm]current page.west) -- cycle;
\path [fill=lightgray]
([yshift=0cm]current page.west) -- ([yshift=0cm,xshift=12cm]current page.west) -- ([yshift=-0.5cm,xshift=12cm]current page.west) -- ([yshift=-0.5cm]current page.west) -- cycle;
\node[font=\bfseries\color{black},anchor=west,
xshift=1cm,yshift=9.5cm] at (current page.west)
{\fontsize{40}{60}\selectfont #1};
\node[font=\bfseries\color{black},anchor=west,
xshift=1cm,yshift=0.5cm] at (current page.west)
{\fontsize{40}{60}\selectfont #2};
\end{tikzpicture}%
}
然后\PageHeader{Header 1}{Header 2}
在每一页上使用类似的内容。
如果您还想在 tikzpicture 环境中添加一些内容,请使用:
\newenvironment{PageHeader}[2]{%
\begin{tikzpicture}[remember picture,overlay, fill]
\path [fill=lightgray]
([yshift=9cm]current page.west) -- ([yshift=9cm,xshift=12cm]current page.west) -- ([yshift=8.5cm,xshift=12cm]current page.west) -- ([yshift=8.5cm]current page.west) -- cycle;
\path [fill=lightgray]
([yshift=0cm]current page.west) -- ([yshift=0cm,xshift=12cm]current page.west) -- ([yshift=-0.5cm,xshift=12cm]current page.west) -- ([yshift=-0.5cm]current page.west) -- cycle;
\node[font=\bfseries\color{black},anchor=west,
xshift=1cm,yshift=9.5cm] at (current page.west)
{\fontsize{40}{60}\selectfont #1};
\node[font=\bfseries\color{black},anchor=west,
xshift=1cm,yshift=0.5cm] at (current page.west)
{\fontsize{40}{60}\selectfont #2};%
}{\end{tikzpicture}}
现在你可以写如下内容:
\begin{PageHeader}{Header 1}{Header 2}
\draw(0,0)--(1,1);
\end{PageHeader}