Tikz 节点定位

Tikz 节点定位

我想尝试使用 tikz 创建封面,并且我想将表格元素放置在彩色 tikz 矩形中,水平左对齐,垂直居中。

在所附示例中,管状体水平居中,垂直居中。如何使表格左对齐,同时保持矩形节点垂直居中?

谢谢

斯图尔特

    \documentclass[a4paper,12pt]{article}
    \usepackage{tikz}

    \begin{document}
        \thispagestyle{empty}
        \begin{tikzpicture}[remember picture,overlay]
                \node (rect) [shape=rectangle, fill=red, minimum height=40mm, minimum width=\paperwidth, anchor=south west] at (current page.south west) {};
                \node [anchor=west] at (rect.center) {
                    \begin{tabular}{|l|r|}
                     A & B \\
                    \end{tabular}
                };
        \end{tikzpicture}
    \end{document}

答案1

由于问题无法明确“左对齐”是指对齐到右边距还是对齐到纸张的右边缘,因此我提供了两个选项;(rect.east)对于前者,将节点定位在 处;对于后者,将节点定位在 处(current page text area.east|-rect.east)(需要tikzpagenodes包)。showframe包只是为页面布局提供视觉指南:

\documentclass[a4paper,12pt]{article}
    \usepackage{tikzpagenodes}
\usepackage{showframe}
    \begin{document}
        \thispagestyle{empty}
        \begin{tikzpicture}[remember picture,overlay]
                \node (rect) [shape=rectangle, fill=red, minimum height=40mm, minimum width=\paperwidth, anchor=south west] at (current page.south west) {};
                \node [anchor=east,inner sep=0pt] at (rect.east) {%
                    \begin{tabular}{|l|r|}
                     A & B \\
                    \end{tabular}%
                };
                \node [anchor=east,inner sep=0pt] at (current page text area.east|-rect.east) {%
                    \begin{tabular}{|l|r|}
                     A & B \\
                    \end{tabular}%
                };
        \end{tikzpicture}
    \end{document}

在此处输入图片描述

相关内容