【问题标题】:pgf/tikz: How to calculate half distance between the x coordinates?pgf/tikz:如何计算 x 坐标之间的半距离?
【发布时间】:2011-06-08 12:53:26
【问题描述】:

我正在尝试创建一个这样的新节点类型:

http://www.live-wtr.ru/leo/Tikz9.png

但不明白,如何计算 x3 = x1 + (x2 - x1) /2

我在这里尝试过,但徒劳无功。

    \pgfdeclareshape{variant}{ \inheritsavedanchors[from=rectangle]
     % this is nearly a rectangle
     \inheritanchorborder[from=rectangle] \inheritanchor[from=rectangle]{center}
     \inheritanchor[from=rectangle]{north} \inheritanchor[from=rectangle]{south}
     \inheritanchor[from=rectangle]{west} \inheritanchor[from=rectangle]{east}

     \backgroundpath{
       %{{{ store lower left in xa/ya and upper right in xb/yb
       \southwest \pgf@xa=\pgf@x \pgf@ya=\pgf@y
       \northeast \pgf@xb=\pgf@x \pgf@yb=\pgf@y
   %}}}

       % compute x3 --- here is the problem!
       \pgf@yc = \pgf@xb - \pgf@xa
       \pgf@yc = 0.5\pgf@yc
       \pgf@xc = \pgf@xa
       \advance \pgf@xc by \pgf@yc

   %end of the problem

       \pgf@yc = \pgf@ya
       \advance\pgf@yc by - 10pt % this should be a parameter

       \southwest \pgf@xa=\pgf@x \pgf@ya=\pgf@y
       %{{{ construct 2 bottom lines
       \pgfpathmoveto{\pgfpoint{\pgf@xa}{\pgf@ya}}
       \pgfpathlineto{\pgfpoint{\pgf@xc}{\pgf@yc}}
       \pgfpathlineto{\pgfpoint{\pgf@xb}{\pgf@ya}}
   %}}}

       % Rectangle box
       \pgfpathrectanglecorners{\southwest}{\northeast}

     }
   }

【问题讨论】:

    标签: latex tikz pgf


    【解决方案1】:

    您可以使用 PGF 数学引擎进行计算。

    % compute x3 --- here is the problem!
    
    \pgfmathparse{(\pgf@xb-\pgf@xa)/2}
    \pgf@xc=\pgf@xa
    \advance\pgf@xc by \pgfmathresult pt
    
    %end of the problem
    

    【讨论】:

    • 当我使用它时,我有一个“警告:在向后兼容模式下运行(不合适的刻度标签;缺少功能)。考虑将 \pgfplotsset{compat=1.8} 写入序言”。如果我这样做,我还有另一个问题:“不完整的 \iffalse;行后所有文本都被忽略...”
    猜你喜欢
    • 1970-01-01
    • 2021-09-08
    • 2020-06-02
    • 2021-04-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多