
에서 사용할 명령을 만들려고 합니다 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:
(예: this 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}