重心 cs で使用する \foreach を使用するコマンドを作成する

重心 cs で使用する \foreach を使用するコマンドを作成する

で使用されるコマンドを作成しようとしていますbarycentric cs:

他のノードの中間にあるノードを取得するのに多くの時間を費やすのでbarycentric cs、自分にとって負担が軽くなるように努めています。また、リストをパラメータとして使用する別のコマンドでも使用されます。

次のようなコードがあるとします:

\documentclass[border=5mm]{standalone}

\usepackage{tikz}

\usetikzlibrary{matrix}
\usetikzlibrary{positioning}

\begin{document}
    \tikzset{
        basic/.style={
            draw, 
            rounded corners=2pt, 
            thick, 
            text width=8em, 
            align=flush center, 
            node distance=2em
        }
    }
    \begin{tikzpicture}
        \matrix[row sep=2em, column sep=4em, every node/.style={basic}] {
            \node(a){text}; & \node(c){text}; \\
            \node(b){text}; & \node(d){text}; \\
            % Loads of other nodes
        };
    \end{tikzpicture}
\end{document}

を使用する代わりに、\node (bc#) at (barycentric cs:a=1,b=1,c=1,d=1,<...>) {text};のみを記述するコマンドを作成しようとしています\node (x) at (baricentric cs:\listforbarycentrics{a,b,c,d}) {text};

このコマンドコードを試してみました:

\newcommand{\listforbarycentrics}[1]{\foreach \n in {#1}{
        \n=1,
    };
}

barycentric cs:しかし、うまくいきません。のリストの末尾にカンマがあるとbarycentric cs:a=1,b=1,c=1,d=1,エラーになるのかもしれませんが、よくわかりません。

答え1

このようなもの?

\documentclass[border=5mm]{standalone}

\usepackage{tikz}

\usetikzlibrary{matrix}
\usetikzlibrary{positioning}

\begin{document}
    \tikzset{
        basic/.style={
            draw, 
            rounded corners=2pt, 
            thick, 
            text width=8em, 
            align=flush center, 
            node distance=2em
        },
        barycentric setup/.code={\foreach \X [count=\Y] in {#1}
        {\ifnum\Y=1
         \xdef\baryarg{\X=1}
        \else
         \xdef\baryarg{\baryarg,\X=1}
        \fi}},
        barycentric list/.style={barycentric setup={#1},insert path={%
        (barycentric cs:\baryarg)}}
    }
    \begin{tikzpicture}
        \matrix[row sep=2em, column sep=4em, every node/.style={basic}] {
            \node(a){text}; & \node(c){text}; \\
            \node(b){text}; & \node(d){text}; \\
            % Loads of other nodes
        };
        \path[barycentric list={a,b,c,d}] node {center}; 
    \end{tikzpicture}
\end{document}

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

関連情報