如何创建可选参数,如果不使用,则引用它的任何内容都会被忽略,而不是处理其默认值?

如何创建可选参数,如果不使用,则引用它的任何内容都会被忽略,而不是处理其默认值?

我需要防止below=0mm of #1通过完全包含样式进行处理(当没有从外部为该样式指定参数时),而不是将#1 恢复为分配给它的默认值。

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary
    {%
        positioning,
        shapes.geometric
    }
\tikzset
    {%
        TRIANGLE/.style=
            {%
% NODE 'T1' WILL FAIL TO COMPILE IF
%  NEXT LINE IS UNCOMMENTED (BECAUSE 'T1' IS A FIRST NODE AND IS NOT BELOW OF ANY OTHER)
%               below=0mm of #1,
%  BUT IF SOLUTION TO MY QUESTION IS FOUND,
%  T1 AND T2 WILL BOTH COMPILE AND BE DISPLAYED PROPERLY
%  WHILE 'below=0mm of #1' IS UNCOMMENTED
                    anchor=apex,
                isosceles triangle,
                minimum width=30mm,
                line width=1mm,
                draw
            }
}
\begin{document}
    \begin{tikzpicture}
% I NEED THE NODE 'T1' TO MAKE 'TRIANGLE' STYLE
%  IGNORE 'below=0mm of #1' ALTOGETHER
%  WITHOUT PROCESSING DEFAULT VALUE OF #1
        \path node[TRIANGLE](T1){};
% ALTHOUGH 'T1' IS PASSED TO THE STYLE,
%  IT IS IGNORED SINCE 'below=0mm of #1' IS COMMENTED
        \path node[TRIANGLE={T1}](T2){};
    \end{tikzpicture}
\end{document}

答案1

为什么你的风格根本不使用参数,而让 TikZ 为你完成这项工作?

\documentclass{standalone}

\usepackage{tikz}
\usetikzlibrary{positioning, shapes.geometric}
\tikzset
    {%
        TRIANGLE/.style=
            {%
                anchor=apex,
                isosceles triangle,
                minimum width=30mm,
                line width=1mm,
                draw
            }
}
\begin{document}
    \begin{tikzpicture}
        \path node[TRIANGLE](T1){};
        \path node[TRIANGLE, below=0mm of T1](T2){};
    \end{tikzpicture}
\end{document}

在此处输入图片描述

相关内容