如何将标签的位置作为参数传递?
\documentclass[tikz,11pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{decorations.pathmorphing,shapes,shapes.geometric,patterns}
\usetikzlibrary{positioning,calc,intersections}
\newcommand*\circled[1]{\tikz[baseline=(char.base)]{
\node[shape=circle,draw,inner sep=2pt] (char) {#1};}}
\begin{document}
\tikzset{
pics/mypic/.style args={#1/#2/#3/#4}{
code = {
\draw[fill=orange] (0,0)rectangle (1,1);
\draw[fill=orange] (1,1)--(2,1)--(1,2)--cycle;
\draw[fill=orange] (2,1)--(2,0)--(1,0)--cycle;
\node[#1] at (0,0) {#2};
\node[#3] at (1,2) {#4};
}
}
}
\begin{tikzpicture}
\draw[blue,thin,step=1.0] (0,0) grid (15,12) ;
\pic at (1,7) {mypic=left/B/left/A};
\pic at (7,1) {mypic=left/N/above left/M};
\pic[rotate=90] at (5,8) {mypic=left/C/above left/D};
\pic[rotate=90] at (13,2) {mypic=left/E/above left/L};
\node at (2,9.5) {\circled{1}};
\node at (3.5,10) {\circled{2}};
\end{tikzpicture}
\end{document}
答案1
哦,这很简单。编辑:我稍微改变了语法以使其发挥作用。
现在,您只需添加at={(x,y)}
到选项pic
即可覆盖默认坐标。我举一个例子,其中我移动了标签C
,并将传递给它{below right,at={(2,1)}}
。
\documentclass[tikz,11pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{decorations.pathmorphing,shapes,shapes.geometric,patterns}
\usetikzlibrary{positioning,calc,intersections}
\newcommand*\circled[1]{\tikz[baseline=(char.base)]{
\node[shape=circle,draw,inner sep=2pt] (char) {#1};}}
\begin{document}
\tikzset{
pics/mypic/.style args={#1/#2/#3/#4}{
code = {
\draw[fill=orange] (0,0)rectangle (1,1);
\draw[fill=orange] (1,1)--(2,1)--(1,2)--cycle;
\draw[fill=orange] (2,1)--(2,0)--(1,0)--cycle;
\node[at={(0,0)},#1] {#2};
\node[at={(1,2)},#3] {#4};
}
},circled/.style={shape=circle,draw,inner sep=2pt}
}
\begin{tikzpicture}
\draw[blue,thin,step=1.0] (0,0) grid (15,12) ;
\pic at (1,7) {mypic=left/B/left/A};
\pic at (7,1) {mypic=left/N/above left/M};
\pic[rotate=90] at (5,8) {mypic={below left,at={(0,1)}}/C/above left/D};
\pic[rotate=90] at (13,2) {mypic=below/E/above left/L};
\node[circled] at (2,9.5) {1};
\node[circled] at (3.5,10) {2};
\end{tikzpicture}
\end{document}