为什么每种路径样式也会影响节点边界?

为什么每种路径样式也会影响节点边界?

如果我添加rounded cornersevery path/.style,该选项也会影响节点边界。为什么?

创建一种在环境中使用的样式是scope避免这种情况的正确方法吗?(当然,实际的流程图\draw比 MWE 更多)。

\documentclass[border=4pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{
    shapes.geometric,
    matrix, 
    arrows.meta}
\begin{document}
    \begin{tikzpicture}[
    basenode/.style={
        draw=gray, align=center,
        text=black, very thick,
        anchor=center,   
        align=center,
    },
    block/.style={
        basenode,  text width=7em, 
        minimum height=8ex,
        inner sep=0pt,
    },
    decision/.style={
        basenode,
        minimum width=12em,
        minimum height=16ex,
        diamond,  
        anchor=center,
        shape aspect=2,
        text width=5em,
        inner sep=0pt,
    },
    %myarrow/.style={
    every path/.style={
        gray, 
        very thick,
        rounded corners,
        -{Triangle[width=5pt]}
    },
    ]
    \matrix[
        matrix of nodes, row sep=5ex, column sep=-2em,
        ] {
     |[decision](a)| A \\
     & |[block](b)| B \\
    };
    %\begin{scope}[myarrow]
    \draw (a) -| (b);
    %\end{scope}
    \end{tikzpicture}
\end{document}

在此处输入图片描述

答案1

\node是 的缩写\path[node],参见手册中的第 15.1 节,所以我认为这并不奇怪。

另一种方法是添加

every node/.append style={sharp corners}

tikzpicture选项。这似乎不会覆盖rounded corners节点样式。

代码输出

\documentclass[border=4pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{
    shapes.geometric,
    matrix, 
    arrows.meta}
\begin{document}
    \begin{tikzpicture}[
    basenode/.style={
        draw=gray, align=center,
        text=black, very thick,
        anchor=center,   
        align=center,
    },
    block/.style={
        basenode,  text width=7em, 
        minimum height=8ex,
        inner sep=0pt,
    },
    decision/.style={
        basenode,
        minimum width=12em,
        minimum height=16ex,
        diamond, 
        anchor=center,
        shape aspect=2,
        text width=5em,
        inner sep=0pt,
    },
    %myarrow/.style={
    every path/.style={
        gray, 
        very thick,
        rounded corners,
        -{Triangle[width=5pt]}
    },
    % addition:
    every node/.append style={sharp corners}
    ]
    \matrix[
        matrix of nodes, row sep=5ex, column sep=-2em,
        ] {
     |[decision](a)| A \\
     & |[block](b)| B \\
    };
    %\begin{scope}[myarrow]
    \draw (a) -| (b);
    %\end{scope}
    \end{tikzpicture}
\end{document}

相关内容