図形やテキストコンテンツを横切る線を描く

図形やテキストコンテンツを横切る線を描く

既存の図形とテキスト コンテンツを横切る可能性のある 2 つのノード間に線を描画します。以下の例では、ノードとノードを接続する線がノードのラベルと交差していますa。Tikzの結果から事実に気付いた後、手動で「線を横切る」ことができます。しかし、このような状況を判断し、実行時に自動的に処理できる機能はありますか? 次のようなものbinit\draw [flyline, ->] (a) to (b)

\documentclass[convert]{standalone}
\usepackage{tikz}
\usetikzlibrary{shapes, positioning}

\begin{document}
    \begin{tikzpicture}[auto]
        \node[rectangle, draw=black, label={right:this is a test}] (init) {hello};
        \node[rectangle, draw=black, above right=of init] (a) {a};
        \node[rectangle, draw=black, below right=of init] (b) {b};
        \draw [->] (a) to (b);
        % I can change to use this after I find the intersect fact from the result
        %\draw (a) to (a|-init.north);
        %\draw [->] (b|-init.south) to (b);
    \end{tikzpicture}
\end{document}

更新: @Rmano のコメントへの返信: 返信ありがとうございます。はい、レイヤーを使用すると、問題を部分的に解決できます。5 つの定義済みレイヤーを提供する `tikz-layers` パッケージを使用しました。コード スニペットは次のとおりです。
\documentclass[convert]{standalone}
\usepackage{tikz}
\usetikzlibrary{shapes, positioning, fit}
\usepackage{tikz-layers}

\begin{document}
    \begin{tikzpicture}[auto]
        \node[rectangle, draw=black, label={[fill=white, inner sep=2pt, name=lbl]right:this is a test}] (init) {hello};
        \node[rectangle, draw=black, above right=of init] (a) {a};
        \node[rectangle, draw=black, below right=of init] (b) {b};
        \begin{scope}[on behind layer]
            \draw [->] (a) to (b);
        \end{scope}
        \begin{scope}[on background layer]
            \node [fit=(init)(a)(b)(lbl), fill=cyan] () {};
        \end{scope}
    \end{tikzpicture}
\end{document}

結果は次のようになる

完璧ではないと感じるのは、ラベルが背景の塗りつぶしを覆ってしまうことです。元々labelはテキストのみでしたが、背景の塗りつぶしに対して透明ではない形状になりました。ラベルの塗りつぶしを背景の塗りつぶしと同じように変更できますcyanが、別の依存関係が作成されます。

下線をマスクするだけで下線をマスクしないlabel仮想境界を持つ可能性はありますか?drawfill


更新: @Rmano の `contour` を使用するという提案に従って、MWE を次のように更新します。
\documentclass[convert]{standalone}
\usepackage{tikz}
\usetikzlibrary{shapes, positioning, fit}
\usepackage{tikz-layers}
\usepackage{bidicontour}
\usepackage{bidi}
\bidicontourlength{2pt}

\begin{document}
    \begin{tikzpicture}[auto]
        \node[rectangle, draw=black, label={[inner sep=2pt, name=lbl]right:{\bidicontour{cyan}{this is a test}}}] (init) {hello};
        \node[rectangle, draw=black, above right=of init] (a) {a};
        \node[rectangle, draw=black, below right=of init] (b) {b};
        \begin{scope}[on behind layer]
            \draw [->] (a) to (b);
        \end{scope}
        \begin{scope}[on background layer]
            \node [fit=(init)(a)(b)(lbl), fill=cyan] () {};
        \end{scope}
        %\draw (a) to (a|-init.north);
        %\draw [->] (b|-init.south) to (b);
    \end{tikzpicture}
\end{document}

ほぼ完璧な結果が得られる

助けてくれてありがとう!

答え1

下線をマスクするだけで下線をマスクしないlabel仮想境界を持つ可能性はありますか?drawfill

そうじゃないと思うよ。

label={[fill=cyan]text}また、私の意見では、と の書き方の間に大きな違いはありませんlabel={[...]\bidicontour{cyan}{text}}。 では、常に背景色を明示的に記述する必要がありますlabel={...}

次の例は、背景色を1回だけ書き込む試みを示しています。pgfonlayerreversed環境の定義は、私の前の回答

\documentclass[tikz]{standalone}
\usetikzlibrary{backgrounds, shapes, positioning, fit}

\usepackage{xpatch}

\makeatletter
% copied from my previous answer https://tex.stackexchange.com/a/562606
\let\pgfonlayerreversed\pgfonlayer
\let\endpgfonlayerreversed\endpgfonlayer

\xpatchcmd\pgfonlayerreversed
  {\expandafter\box\csname pgf@layerbox@#1\endcsname\begingroup}
  {\begingroup}
  {}{\fail}

\xpatchcmd\endpgfonlayerreversed
  {\endgroup}
  {\endgroup\expandafter\box\csname pgf@layerbox@\pgfonlayer@name\endcsname}
  {}{\fail}

% similar to \tikz@background@framed, but using "pgfonlayerreversed" envi
\def\tikz@background@framed@reversed{%
  \tikz@background@save%
  \pgfonlayerreversed{background}
    \path[style=background rectangle] (\tikz@bg@minx,\tikz@bg@miny) rectangle (\tikz@bg@maxx,\tikz@bg@maxy);
  \endpgfonlayerreversed
}%

% similar to option "show background rectangle"
\tikzset{
  show background rectangle reversed/.style={
    execute at end picture=\tikz@background@framed@reversed
  }
}
\makeatother

% user interface
\tikzset{
  background color/.style={
    show background rectangle reversed,
    inner frame sep=2pt,
    background rectangle/.append style={draw=none, #1},
    every node/.append style={#1},
    every label/.append style={#1}
  }
}

\begin{document}
    \begin{tikzpicture}[background color={fill=cyan}]
        \node[draw, label={[inner sep=2pt, name=lbl]right:this is a test}] (init) {hello};
        \node[draw, above right=of init] (a) {a};
        \node[draw, below right=of init] (b) {b};
        
        \begin{scope}[on background layer]
            \draw [->] (a) to (b);
        \end{scope}
    \end{tikzpicture}
\end{document}

ここに画像の説明を入力してください

関連情報