将两个 tikz 节点的中心置于页面的中心

将两个 tikz 节点的中心置于页面的中心

请考虑以下示例:

\documentclass[twoside, 10pt]{book}
\usepackage[
    paperwidth=6in,
    paperheight=9in,
    tmargin=0.75in,
    bmargin=0.75in,
    inner=0.75in,
    outer=0.75in
]{geometry}
\usepackage{calc}
\usepackage{tikz}
\usepackage{etoolbox}
\usepackage{transparent}
\usepackage{tikzpagenodes}
\usepackage[table]{xcolor}
\usetikzlibrary{calc}
\usetikzlibrary{fadings}
\usetikzlibrary{shadows.blur}
\usetikzlibrary{matrix}
\pagestyle{empty}

\begin{document}

\tikz[remember picture, overlay]{
    \node[
        circle,
        fill = black,
        font = \sffamily\fontsize{24}{24}\bf\selectfont\color{white},
        anchor = west,
        minimum size = 1.5cm,
        outer sep = 0pt
    ] at (current page text area.center) (numb) {I};
    \node[
        anchor = east,
        inner sep = 0pt,
        outer sep = 0pt,
        font = \sffamily\fontsize{48}{48}\selectfont
    ] at ($(numb.west) + (-0.5cm, 0cm)$) {
        This is part 
    };
}

\end{document}

输出结果如下:

图片示例

目前,第一个节点的西边位于页面的中心。除此之外,如何将两个节点(好像只有一个大节点)的中心与页面文本区域的中心水平居中?(我正在 tikz 环境中搜索命令,而不是全局命令来\begin{center} \end{center}包装 tikz 图形。)换句话说,最终结果应该是将“这是第一部分”水平居中在页面的文本区域。

答案1

您可以使用\matrix

\documentclass[twoside, 10pt]{book}
\usepackage[
    paperwidth=6in,
    paperheight=9in,
    tmargin=0.75in,
    bmargin=0.75in,
    inner=0.75in,
    outer=0.75in
]{geometry}
\usepackage{calc}
\usepackage[table]{xcolor}

\usepackage{etoolbox}
\usepackage{transparent}
\usepackage{tikzpagenodes}
\usetikzlibrary{calc}
\usetikzlibrary{fadings}
\usetikzlibrary{shadows.blur}
\usetikzlibrary{matrix}
\pagestyle{empty}

\begin{document}

\tikz[remember picture, overlay]{
  \matrix [column sep=5mm] at (current page text area.center) {
    \node[
        anchor = east,
        inner sep = 0pt,
        outer sep = 0pt,
        font = \sffamily\fontsize{48}{48}\selectfont
    ] {This is part};
 &
    \node[
        circle,
        fill = black,
        font = \sffamily\fontsize{24}{24}\bf\selectfont\color{white},
        anchor = west,
        minimum size = 1.5cm,
        outer sep = 0pt
    ]  (numb) {I};
\\
};
}

\end{document}

相关内容