如何获取线宽和内部分隔值?

如何获取线宽和内部分隔值?

我尝试获取线宽和节点内分隔的值。如何从自己的样式中读取这样的值(如果在修改图片时会指定)或者如果此样式中未指定,如何获取绘制线或节点时应用的值?

代码:

\documentclass{standalone}
\usepackage{tikz}

\begin{document}
\begin{tikzpicture}[
    every node/.style={line width=2pt},
    my line style/.style={very thick},
    my node style1/.style={draw,inner sep=1em},
    my node style2/.style={draw}
]
    \pgfkeys{/pgf/inner xsep/.get=\innerxsep}
    \node at (0,0) [my node style2,anchor=west] {x inner sep = \innerxsep};

    %\pgfkeys{ ????  /.get=\innerxsep} % how to read inner sep value applied while "my node style1" is used,
                                       % independently on if it is specified in this style?
                                       % how to read border width value applied while "my node stylei" is used,
                                       % independently on if it is specified in this style?
    \node at (0,-1) [my node style1,anchor=west] {x inner sep = ?, border width = ?};

    %\pgfkeys{ ????  /.get=\lw} % how to read line width value applied while "my line style" is used,
                                % independently on if it is specified in this style?
    \draw [my line style] (0,-2) -- +(1,0) node [right] {line width=?};
\end{tikzpicture}
\end{document}

我尝试按照@Loop Space 给出的答案(读取 - 以及效果 - (默认) tikz/pgf 键?)和@Andrew Swann(检查 pgfkey 的值),但我的问题没有成功。

答案1

您自己的风格不会改变线宽和内部分隔设置的任何固有属性。因此,您仍然可以使用常规的键设置/读取方式。

\documentclass[tikz]{standalone}
\begin{document}
\begin{tikzpicture}[
    every node/.style={line width=2pt},
    my line style/.style={very thick},
    my node style1/.style={draw,inner sep=1em},
    my node style2/.style={draw}
]
    \node at (0,0) [my node style2,anchor=west] 
         {x inner sep = \pgfkeysvalueof{/pgf/inner xsep}};
    \node at (0,-1) [my node style1,anchor=west] 
         {x inner sep = \pgfkeysvalueof{/pgf/inner xsep}, border width = \the\pgflinewidth};
    \draw [my line style] (0,-2) -- +(1,0) node [right] {line width=\the\pgflinewidth};
\end{tikzpicture}
\end{document}

在此处输入图片描述

相关内容