亲爱的 tikzperts:我该如何保持框中文本的方向,以便 .pic 内的旋转可以添加到主文本中的旋转中。
\documentclass[border=3mm,12pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{calc}
\tikzset{
testboxtext/.pic={
\draw[black, fill=gray] (0,0) rectangle (60,40);
\draw[fill=white] (20,20) rectangle (25,35) node[pos=0.5,rotate=90] { some text };
}
}
\begin{document}
\begin{tikzpicture}
\draw[step=1, gray, very thin] (-1,-1) grid (101,101);
\pic[rotate=90] at (10,10) {testboxtext};
\end{tikzpicture}
\end{document}
这几乎就像我需要“内旋转”和“外旋转”,或双重旋转,这样我就不会得到覆盖。
谢谢您的建议。
答案1
我很难相信这是你真正想要的,但我目前找不到对你的问题的另一种解释。
\documentclass[border=10pt,tikz,multi]{standalone}
\tikzset{%
testboxtext/.pic={%
code={
\tikzset{%
test box text/.cd,
#1
}
\draw [black, fill=gray] (0,0) rectangle (6,4);
\draw [fill=white, draw=red] (2,2) rectangle (2.5,3.5) node [rotate=90+\additionalrotation, pos=.5] { some text };
}
},
test box text/.search also={/tikz},
test box text/.cd,
rotate/.store in=\additionalrotation,
rotate=0,
}
\begin{document}
\begin{tikzpicture}
\draw [help lines] (-1,-1) grid (11,11);
\pic at (5,5) {testboxtext};
\pic at (1,1) {testboxtext={rotate=90}};
\end{tikzpicture}
\end{document}
请注意,我大大缩小了矩形的尺寸,因为文本太小了,否则根本无法显示。我只能假设你有一个足球场大小的显示器。因为我没有,所以这些尺寸对我来说太大了。
答案2
确保\pic
环境内节点文本正确旋转的另一种方法是将[every node/.style={transform shape}]
选项传递给 tikz 图片:
\documentclass[border=10pt,tikz,multi]{standalone}
\tikzset{%
testboxtext/.pic={%
code={
\tikzset{%
test box text/.cd,
#1
}
\draw [black, fill=gray] (0,0) rectangle (6,4);
\draw [fill=white, draw=red] (2,2) rectangle (2.5,3.5) node [rotate=90+\additionalrotation, pos=.5] { some text };
}
},
test box text/.search also={/tikz},
test box text/.cd,
rotate/.store in=\additionalrotation,
rotate=0,
}
\begin{document}
\begin{tikzpicture}
\draw [help lines] (-1,-1) grid (11,11);
\pic at (5,5) {testboxtext};
\pic[rotate=90] at (3,1) {testboxtext};
\end{tikzpicture}
%
\begin{tikzpicture}[every node/.style={transform shape}]
\draw [help lines] (-1,-1) grid (11,11);
\pic at (5,5) {testboxtext};
\pic[rotate=90] at (3,1) {testboxtext};
\end{tikzpicture}
\end{document}