节点基错误

节点基错误

这里遇到一个奇怪的问题:我有一个节点样式,我已将其用于许多流程图。它的基座始终位于形状的正中央,但现在它已向上平移约 1/4 朝向北锚点。蓝线和红线清楚地显示它已向北移动,但基座diamond仍位于正中央。这是怎么回事?

节点库

\documentclass{article}

\usepackage{tikz}
\usepackage[margin=0.5in]{geometry}
\pagestyle{empty}

\begin{document}

%\input{../tikz-setup.tex}
\usetikzlibrary{shapes, arrows, calc, positioning, matrix}

% Define block styles
\tikzstyle{state}   = [ rounded rectangle, 
                        draw, 
                        text centered, 
                        minimum height=3em ,
                        minimum width = 6em,
                        inner sep = 5pt
                      ]
\tikzstyle{test}    = [ diamond, 
                        draw, 
                        shape aspect=2, 
                        inner sep = 0pt,
                        text width = 7em,
                        text centered
                      ]
\tikzstyle{action}  = [ rectangle, draw,
                        text width=8em,
                        inner sep = 3pt, 
                        minimum height=5em
                      ]
\tikzstyle{data}    = [ trapezium, 
                        draw, 
                        trapezium left angle=60, 
                        trapezium right angle=120pt,
                        minimum height = 6em, 
                        text width = 5em,
                        inner xsep = 0pt
                       ]
\tikzstyle{line}    = [ draw, -triangle 45 ]

\tikzstyle{list}  = [ rectangle, draw,
                        minimum width = 6em                      
                      ]

\tikzstyle{ptr-box}  = [ rectangle, 
                        text width = 8em                      
                      ]

\begin{center}
\begin{tikzpicture}[align = flush center, font = \small]

    \matrix [matrix of nodes, column sep = 1em, row sep = 2em,
                nodes={},
                ] (end-mtrx)
    {     
    |[action] (a)| Lorem ipsum dolor sit amet, consectetur adipiscing elit \\
    |[test] (b)| Lorem ipsum dolo  \\        
    |[test] (c)| Lorem ipsum  \\ 
    |[test] (d)| Lorem ipsum dolor & |[action] (e)| Lorem ipsum dolor sit amet, consectetur adipiscing elit \\
    |[state] (f)| Lorem ipsum d & |[state] (g)| Lorem ipsum dolor  & |[state] (bad-sd)| Lorem ipsum dolo\\
     };

     \path[draw, red, line width=5pt] (d.base) -- (e.base);

     \path[draw, blue, line width=5pt] (a.base) -- +(3,0);


\end{tikzpicture}
\end{center}
\end{document}

答案1

节点通常在其基线对齐。

您可以使用键来移动它anchor(手册的第 16.5 节“定位节点” PFG/TikZ)。
我想补充anchor=center一下矩阵规范:

\begin{tikzpicture}[align = flush center, font = \small]
    \matrix [matrix of nodes, column sep = 1em, row sep = 2em,
                nodes={anchor=center},
                ] (end-mtrx)
    {     
    |[action] (a)| Lorem ipsum dolor sit amet, consectetur adipiscing elit \\
    |[test] (b)| Lorem ipsum dolo  \\        
    |[test] (c)| Lorem ipsum  \\ 
    |[test] (d)| Lorem ipsum dolor & |[action] (e)| Lorem ipsum dolor sit amet, consectetur adipiscing elit \\
    |[state] (f)| Lorem ipsum d & |[state] (g)| Lorem ipsum dolor  & |[state] (bad-sd)| Lorem ipsum dolo\\
     };

     \path[draw, red, line width=5pt] (d.center) -- (e.center);
     \path[draw, blue, line width=5pt] (a.center) -- +(3,0);
     \path[draw, red,] (d.base) -- (e.base);
     \path[draw, blue,] (a.base) -- +(3,0);
\end{tikzpicture}

输出

示例输出

相关内容