我正在生成大量图形tikz
,我需要在文档的各个位置以及动画中重复使用这些图形。因此,我正在预先创建所有这些图。为了确保图中所有页面大小都相同,我使用了几何包。水平居中很容易,但即使经过大量观察,我还是无法弄清楚如何在整个页面上垂直居中 tikz 图形。以下是一个例子:
\documentclass{article}
\usepackage{tikz}
\usepackage[ paperwidth=4cm,paperheight=4cm]{geometry}
\begin{document}
\begin{center}
\begin{tikzpicture}
\draw node[fill,circle,minimum size=2cm] {};
\end{tikzpicture}
\end{center}
\end{document}
这使得:
如何获取位于页面正中心的节点?
答案1
使用current page
节点(参见 tikz 文档第 17.13.2 条):
\documentclass{article}
\usepackage{tikz}
\usepackage[ paperwidth=4cm,paperheight=4cm]{geometry}
\begin{document}
\begin{tikzpicture}[remember picture, overlay]
\draw node[fill,circle,minimum size=2cm] at (current page.center) {};
\end{tikzpicture}
\end{document}
在同一个 tikzpicture 中有2个节点:
\documentclass{article}
\usepackage{tikz}
\usepackage[ paperwidth=4cm,paperheight=4cm]{geometry}
\begin{document}
\begin{tikzpicture}[remember picture, overlay]
\draw node[fill,circle,minimum size=2cm] at (current page.center) {};
\draw node[fill=blue, rectangle, minimum size=2cm] at
(current page.north) {};
\end{tikzpicture}
\end{document}
并有2张 tikzpicture :
\documentclass{article}
\usepackage{tikz}
\usepackage[ paperwidth=4cm,paperheight=4cm]{geometry}
\begin{document}
\begin{tikzpicture}[remember picture, overlay]
\draw node[fill,circle,minimum size=2cm] at (current page.center) {};
\draw node[fill=blue, rectangle, minimum size=2cm] at
(current page.north) {};
\end{tikzpicture}
\begin{tikzpicture}[remember picture, overlay]
\draw node[fill=red, circle,minimum size=5mm, anchor=south west,
xshift=5mm, yshift=5mm] at
(current page.south west) {};
\end{tikzpicture}
\end{document}