在 tikz 链式图中对齐节点

在 tikz 链式图中对齐节点

我从此开始我的工作例子

清理代码以更好地理解命令后,我遇到了这种情况

\begin{tikzpicture}[
    scale=0.75,
    start chain=1 going below, 
    start chain=2 going right,
    node distance=3mm,
    blocksgeneric/.style={
        scale=0.75,
        on chain=2,
        rectangle,
        rounded corners,
        draw=black, 
        very thick,
        text centered,
        text width=8cm,
        minimum height=12mm,
        fill=black!10
        },
    blocksblue/.style={
        fill=blue!30
    },
    labels/.style={
        scale=0.75,
        on chain=1,
        minimum height=12mm,
        text width=2cm,
        text centered
    },
    every node/.style={font=\sffamily}
]

% Left column
\node [labels] (L5) {L5};
\node [labels] (L4) {L4};
\node [labels] (L3) {L3};
\node [labels] (L2) {L2\\L2\\L2\\L2\\L2\\L2};
\node [labels] (L1) {L1};
\node [labels] (L0) {L0};

% Right column
\chainin (L5); % Start right of L5

\node [blocksgeneric] (B5) {B5};
\node [blocksgeneric, blocksblue, continue chain=going below] (B4) {B4};
\node [blocksgeneric] (B3) {B3};
\node [blocksgeneric] (B2) {B2};
\node [blocksgeneric] (B1) {B1};
\node [blocksgeneric] (B0) {B0};

\end{tikzpicture}

结果就是这样。

我想要的是将 L2 标签以相同的方式保留在 B2 块和其他块旁边。

编辑 1:如果我想自定义右侧某个块的高度以表示更大的概念,我该怎么做?左侧的标签应位于块的中心。同时,如果一个块比包含大量文本的标签小(因为我希望它小),我如何才能使块保持较小,同时将其放在左侧文本的中心?

编辑 2:最后一个问题:如果我想将块 B2 的尺寸扩展到标签 L2 的尺寸(取决于实际高度)我该怎么做?

答案1

您可以使用 来定位节点,而不是使用链\matrix,其行为类似于tabular具有动态列的环境。如果您想了解更多信息,请查看 PGFmanual。

我在那里修好了它

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{matrix}

\begin{document}
\begin{tikzpicture}[
    scale=0.75,
    blocksgeneric/.style={
        scale=0.75,
        rectangle,
        rounded corners,
        draw=black, 
        very thick,
        text centered,
        text width=8cm,
        minimum height=12mm,
        fill=black!10
        },
    blocksblue/.style={
        fill=blue!30
    },
    labels/.style={
        scale=0.75,
        minimum height=12mm,
        text width=2cm,
        text centered
    },
    every node/.style={font=\sffamily}
]

% Left column

\matrix[row sep=3mm]{
    \node [labels] (L5) {L5}; &
    \node [blocksgeneric] (B5) {B5}; \\

    \node [labels] (L4) {L4}; &
    \node [blocksgeneric, blocksblue] (B4) {B4\\B4\\B4\\B4\\B4}; \\

    \node [labels] (L3) {L3}; &
    \node [blocksgeneric] (B3) {B3}; \\

    \node [labels] (L2) {L2\\L2\\L2\\L2\\L2\\L2}; &
    \node [blocksgeneric] (B2) {B2}; \\

    \node [labels] (L1) {L1}; &
    \node [blocksgeneric] (B1) {B1}; \\

    \node [labels] (L0) {L0}; &
    \node [blocksgeneric] (B0) {B0}; \\
};

\end{tikzpicture}
\end{document}

相关内容