我是 tikz 新手,正在尝试学习如何使用它来为正在编写的报告绘制整页封面。我已成功更改边距并可以渲染到整页,但我很难理解如何从页面底部在固定的绝对位置绘制矩形。我想将表格放入矩形节点以在水印图像上显示名称块。
所以我的问题是,如何在页面上的绝对位置绘制蓝色和红色节点?我还可以指定节点(矩形)的高度(例如 4 厘米)并将表格垂直置于该矩形的中心吗?
在我的代码中,我可以看到顶部的蓝色矩形。
\documentclass[a4paper,12pt]{article}
\usepackage{tikz}
\usepackage[left=5.2cm,top=2cm,right=1.5cm,bottom=2cm,verbose,nohead,nofoot]{geometry}
\usepackage{etoolbox}
% Set up full page to draw in
\AfterEndEnvironment{myfullpage}{\restoregeometry}
\newenvironment{myfullpage}{%
\newgeometry{left=0cm,top=0cm,right=0cm,bottom=0cm,nohead,nofoot}%
}{%
\newpage%
}
\begin{document}
\begin{myfullpage}
\begin{tikzpicture}[remember picture,overlay,shift={(current page.south west)}]
%\node [inner sep=0pt,above right] {\includegraphics[width=\paperwidth]{matrix.eps}};
% Draw a full page width filled rectangle with tabular over at bottom of page
\begin{tikzpicture}[remember picture,overlay, anchor = west]
\node (names) [shape=rectangle,fill=blue,minimum width =\paperwidth] {
\begin{tabular}{r l}
A & B
\end{tabular}
};
\end{tikzpicture}
% Draw a full page width filled rectangle with tabular over 8 cm from page current page.south west
\begin{tikzpicture}[remember picture,overlay, shift={(0 cm, 8cm)}, anchor=west]
\node (names) [shape=rectangle,fill=red,minimum width =\paperwidth] {
\begin{tabular}{r l}
one & two
\end{tabular}
};
\end{tikzpicture}
\end{tikzpicture}
\end{myfullpage}
\end{document}
答案1
像这样吗?
请注意,tikzpicture
应尽可能避免嵌套,因为它会导致问题。
这里不需要改变geometry
:我们可以使用相对于页面本身的绝对坐标,例如(current page.center)
进行定位:
\documentclass[a4paper,12pt]{article}
\usepackage{tikz}
\usepackage[left=5.2cm,top=2cm,right=1.5cm,bottom=2cm,verbose,nohead,nofoot]{geometry}
\usepackage{etoolbox}
\begin{document}
\thispagestyle{empty}
\begin{tikzpicture}[remember picture,overlay]
\node (back names) [shape=rectangle, fill=blue, minimum height=40mm, minimum width=\paperwidth, anchor=south west] at (current page.south west) {};
\node at (back names.center) {
\begin{tabular}{r l}
A & B
\end{tabular}
};
\node (names) [shape=rectangle, fill=red, minimum width=\paperwidth, anchor=west] at ([yshift=8cm]current page.south west) {
\begin{tabular}{r l}
one & two
\end{tabular}
};
\end{tikzpicture}
\end{document}
表格最容易居中的方式是绘制后带锚的蓝色矩形center
。
请注意,命名两个节点没有多大意义names
。如果您需要引用节点,则它们需要唯一的名称。如果不需要,它们根本不需要名称。
答案2
可以通过适当选择锚点(current page
)和一些转变来实现:
\documentclass[a4paper,12pt]{article}
\usepackage{tikz}
\usepackage[left=5.2cm,top=2cm,right=1.5cm,bottom=2cm,verbose,nohead,nofoot]{geometry}
\begin{document}
\thispagestyle{empty}
\begin{tikzpicture}[remember picture,overlay, anchor = west]
\node[fill=blue,anchor=north,minimum height=4cm, minimum width=\paperwidth] (names)
at ([yshift=4cm]current page.south) {
\begin{tabular}{r l}
A & B
\end{tabular}
};
\node[fill=red,anchor=south, minimum width=\paperwidth] (names)
at ([yshift=8cm]current page.south) {
\begin{tabular}{r l}
one & two
\end{tabular}
};
\end{tikzpicture}
\end{document}