使用以下修改后的代码这个帖子
如何指定每个图形中心的节点,以便它们可以相对于彼此的中心进行绘制,而不是位置 (0,0)。
\documentclass{article}
\usepackage{tikz}
\tikzset{
big triangle/.pic={
\path[pic actions] (0,0) -- (2,0) -- (2,2) -- cycle;
},
medium triangle/.pic={
\path[pic actions] (0,0) -- (1,1) -- (2,0) -- cycle;
},
square/.pic={
\path[pic actions] (0,0) -- (1,0) -- (1,1) -- (0,1) -- cycle;
},
small triangle/.pic={
\path[pic actions] (0,0) -- (1,0) -- (1,1) -- cycle;
},
parallelogram/.pic={
\path[pic actions] (0,0) -- (1,0) -- (2,1) -- (1,1) -- cycle;
}
}
\tikzset{
tangram solution/.style={
fill=none,
draw=red,
line width=.1mm
},
tangram/.style={
transform shape,
tangram solution
}
}
\begin{document}
\hskip -2cm
\begin{tikzpicture}[scale=2]
\path (0,0) pic[tangram,rotate=0] {big triangle}
--++(0:2) pic[tangram,rotate=0] {parallelogram}
--++(0:1) pic[tangram,rotate=0] {small triangle}
--++(0:1) pic[tangram,rotate=0] {square}
--++(0:1) pic[tangram,rotate=0] {medium triangle}
;
\end{tikzpicture}
\end{document}
答案1
\path
这里,每个中都添加了手动计算的坐标偏移pic
。
\documentclass{article}
\usepackage{tikz}
\tikzset{
big triangle/.pic={
\path[pic actions, shift={(-4/3,-2/3)}] (0,0) -- (2,0) -- (2,2) -- cycle;
\fill circle (1pt); % mark the "center", just for the test
},
medium triangle/.pic={
\path[pic actions, shift={(-1,-1/3)}] (0,0) -- (1,1) -- (2,0) -- cycle;
\fill circle (1pt);
},
square/.pic={
\path[pic actions, shift={(-.5,-.5)}] (0,0) -- (1,0) -- (1,1) -- (0,1) -- cycle;
\fill circle (1pt);
},
small triangle/.pic={
\path[pic actions, shift={(-2/3,-1/3)}] (0,0) -- (1,0) -- (1,1) -- cycle;
\fill circle (1pt);
},
parallelogram/.pic={
\path[pic actions, shift={(-1,-.5)}] (0,0) -- (1,0) -- (2,1) -- (1,1) -- cycle;
\fill circle (1pt);
}
}
\tikzset{
tangram solution/.style={
fill=none,
draw=red,
line width=.1mm
},
tangram/.style={
transform shape,
tangram solution
}
}
\begin{document}
\hskip -2cm
\begin{tikzpicture}[scale=2]
\path (0,0) pic[tangram,rotate=0] {big triangle}
-- ++(0:2) pic[tangram,rotate=0] {parallelogram}
-- ++(0:1) pic[tangram,rotate=0] {small triangle}
-- ++(0:1) pic[tangram,rotate=0] {square}
-- ++(0:1) pic[tangram,rotate=0] {medium triangle};
\end{tikzpicture}
\end{document}