
我正在嘗試創建一個將在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:
(like 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}