![使 tikzpicture 相对于页面(标题页)垂直居中](https://linux22.com/image/474425/%E4%BD%BF%20tikzpicture%20%E7%9B%B8%E5%AF%B9%E4%BA%8E%E9%A1%B5%E9%9D%A2%EF%BC%88%E6%A0%87%E9%A2%98%E9%A1%B5%EF%BC%89%E5%9E%82%E7%9B%B4%E5%B1%85%E4%B8%AD.png)
在下面的 MWE 中,我必须手动偏移 tikzpicture 以使其相对于页面垂直居中对齐。有没有办法让它自动执行此操作?如果 tikzpicture 的长度发生变化,定位也会发生变化。
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{positioning,calc}
\def\titlineoffset{1.5}
\def\titlineabove{1.5}
\def\titlinebelow{3}
\newcounter{lastitlenode}\setcounter{lastitlenode}{1} %
\NewDocumentCommand{\addtitele}{ O{1.0} O{\normalfont} D(){} m }{% TODO figure out how to get away without needing node names in (), it throws an error
\stepcounter{lastitlenode}
\node[font={#2}, below=#1 of lastnode.south west, anchor=north west] (\IfValueTF{#3}{#3}{lastnode\thelastitlenode}) {#4};
\coordinate (lastnode) at (\IfValueTF{#3}{#3}{lastnode\thelastitlenode}.south west);
}
\NewDocumentCommand{\setlastnode}{m}{%
\coordinate (lastnode) at (#1.south west);
}
\def\maketitle{\begin{titlepage}%
\begin{tikzpicture}[overlay,remember picture,
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
shift={($(current page.west)+(5.8, 7.0)$)}, anchor=west, % <-------- RIGHT HERE. If
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% I have to manually off-set the y-shift \
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% I want it such that if I change the 7.0 to zero, the picture is centered vertically
node distance=1cm,
every node/.style={anchor=west,inner sep=0pt,align=left},]
\node[font={\LARGE\bfseries}] (title) {title\\title\\}; \setlastnode{title}
\addtitele[1][\itshape](sub){subtitle\\sub\\sub}
\addtitele[0.5][\itshape\bfseries](deg){Master of Science}
\addtitele[0.5][\itshape](by){by}
\addtitele[1][\Large\bfseries](auth){author}
\addtitele[1.5](publi){publishers}
\addtitele[2.5](date){date}
\draw ($(title.north west)+(-\titlineoffset,\titlineabove)$) |- ($(lastnode.south west)+(-\titlineoffset,-\titlinebelow)$);
\end{tikzpicture}%
\end{titlepage}%
\clearpage
}
\begin{document}
\maketitle
\section{Hello world}
\end{document}
我希望 tikzpicture 的中心以页面为中心作为我的参考,并且如果需要的话允许从那里进行 y 偏移。