
このコード:
\pic[rotate=40, local bounding box=microfono] at (4.5,-5) {microph};
\draw[black, line width=2pt] (microfono.-45) -- ++(-.2,+.2) ++(.2,-.2) -- ++(0,-2);
外側では機能しますscope
が、内側では機能しません (線が表示されません)。なぜでしょうか?
\documentclass[border=0pt]{standalone}
\usepackage{tikz}
\tikzset{
pics/microph/.style={code={
\draw[black, line width=.2em, rounded corners=1.7ex]
(-.85em,4.5ex) -- (-.85em,2ex) -- (.85em,2ex) -- (.85em,4.5ex);
\fill[black]
(-.6em,5ex) to[rounded corners=1.2ex]
(-.6em,2.5ex) to[rounded corners=1.2ex] (.6em,2.5ex)
-- (.6em,5ex) to[rounded corners=.2ex] ++(-.85em,0) to[rounded corners=.2ex] ++(0,.35ex) -- ++(.85em,0)
-- (.6em,5.5ex) to[rounded corners=.2ex] ++(-.85em,0) to[rounded corners=.2ex] ++(0,.35ex) -- ++(.85em,0)
-- (.6em,6ex) to[rounded corners=.2ex] ++(-.85em,0) to[rounded corners=.2ex] ++(0,.35ex) -- ++(.85em,0)
-- (.6em,6.5ex) to[rounded corners=.2ex] ++(-.85em,0) to[rounded corners=.2ex] ++(0,.35ex) -- ++(.85em,0)
to[rounded corners=1.2ex]
(.6em,8ex) to[rounded corners=1.2ex]
(-.6em,8ex) to cycle;
}},
}
\begin{document}
\begin{tikzpicture}
\begin{scope}
\clip (-8.5,-6.5) rectangle (8.5,6.5);
\node[fill=cyan, draw=cyan, minimum width=17cm, minimum height=13cm](sky){};
\pic[rotate=40, local bounding box=microfono] at (4.5,-5) {microph};
\draw[black, line width=2pt] (microfono.-45) -- ++(-.2,+.2) ++(.2,-.2) -- ++(0,-2);
\end{scope}
\end{tikzpicture}
\end{document}
答え1
local bounding box
私はもともと、PGF 3.1.5 で を無条件に実行することで\pgf@path@size@hook
のこの使用を修正していました\pgf@protocolsizes
。しかし、これは の他のすべての の使用を壊してしまいましたlocal bounding box
。残念ながら、この非常にニッチな状況を機能させる別の解決策は思いつきませんでした。それでも、コンテキストlocal bounding box
でを使用する回避策を提案できます\clip
。overlay=false
ローカル境界ボックスを取得したいパスまたはスコープに を追加するだけです。
\documentclass[border=0pt]{standalone}
\usepackage{tikz}
\tikzset{
pics/microph/.style={code={
\draw[black, line width=.2em, rounded corners=1.7ex]
(-.85em,4.5ex) -- (-.85em,2ex) -- (.85em,2ex) -- (.85em,4.5ex);
\fill[black]
(-.6em,5ex) to[rounded corners=1.2ex]
(-.6em,2.5ex) to[rounded corners=1.2ex] (.6em,2.5ex)
-- (.6em,5ex) to[rounded corners=.2ex] ++(-.85em,0) to[rounded corners=.2ex] ++(0,.35ex) -- ++(.85em,0)
-- (.6em,5.5ex) to[rounded corners=.2ex] ++(-.85em,0) to[rounded corners=.2ex] ++(0,.35ex) -- ++(.85em,0)
-- (.6em,6ex) to[rounded corners=.2ex] ++(-.85em,0) to[rounded corners=.2ex] ++(0,.35ex) -- ++(.85em,0)
-- (.6em,6.5ex) to[rounded corners=.2ex] ++(-.85em,0) to[rounded corners=.2ex] ++(0,.35ex) -- ++(.85em,0)
to[rounded corners=1.2ex]
(.6em,8ex) to[rounded corners=1.2ex]
(-.6em,8ex) to cycle;
}},
}
\begin{document}
\begin{tikzpicture}
\begin{scope}
\clip (-8.5,-6.5) rectangle (8.5,6.5);
\node[fill=cyan, draw=cyan, minimum width=17cm, minimum height=13cm](sky){};
\pic[rotate=40, overlay=false, local bounding box=microfono] at (4.5,-5) {microph};
\draw[black, line width=2pt] (microfono.-45) -- ++(-.2,+.2) ++(.2,-.2) -- ++(0,-2);
\end{scope}
\end{tikzpicture}
\end{document}
答え2
の説明には、\clip
「後続のパスのサイズは画像サイズには重要ではありません」という文が含まれています。そのため、local bounding box
正しいサイズを取得できないと想定しています。
簡単な回避策は、マイクロを 2 回描画することです。
\documentclass[border=0pt]{standalone}
\usepackage{tikz}
\tikzset{
pics/microph/.style={code={
\draw[black, line width=.2em, rounded corners=1.7ex]
(-.85em,4.5ex) -- (-.85em,2ex) -- (.85em,2ex) -- (.85em,4.5ex);
\fill[black]
(-.6em,5ex) to[rounded corners=1.2ex]
(-.6em,2.5ex) to[rounded corners=1.2ex] (.6em,2.5ex)
-- (.6em,5ex) to[rounded corners=.2ex] ++(-.85em,0) to[rounded corners=.2ex] ++(0,.35ex) -- ++(.85em,0)
-- (.6em,5.5ex) to[rounded corners=.2ex] ++(-.85em,0) to[rounded corners=.2ex] ++(0,.35ex) -- ++(.85em,0)
-- (.6em,6ex) to[rounded corners=.2ex] ++(-.85em,0) to[rounded corners=.2ex] ++(0,.35ex) -- ++(.85em,0)
-- (.6em,6.5ex) to[rounded corners=.2ex] ++(-.85em,0) to[rounded corners=.2ex] ++(0,.35ex) -- ++(.85em,0)
to[rounded corners=1.2ex]
(.6em,8ex) to[rounded corners=1.2ex]
(-.6em,8ex) to cycle;
}},
}
\begin{document}
\begin{tikzpicture}
%
\begin{scope}
\pic[rotate=40, local bounding box=microfono] at (4.5,-5) {microph};
\clip (-8.5,-6.5) rectangle (8.5,6.5);
\node[fill=cyan, draw=cyan, minimum width=17cm, minimum height=13cm](sky){};
\pic[rotate=40] at (4.5,-5) {microph};
\draw[line width=2pt] (microfono.-45) -- ++(-.2,+.2) ++(.2,-.2) -- ++(0,-2);
\end{scope}
\end{tikzpicture}
\end{document}
答え3
ここではローカル境界ボックスは必要ありません。マイクの座標を使用することができます。ただし、pic
名前のプレフィックスがおかしくなることが知られています。このバグは部分的にしか修正されていませんが、Henri Menkeによると、pgfの次のバージョンで完全に修正される予定です。当面は、@cfr の解決策名前のプレフィックスをリセットしますname prefix ..
。この解決策は、pgfマニュアルv3.1.4の263ページで推奨されているものです。
次に、pgfmanual のトリックを使用して、pic に名前を付け、外部からその座標の 1 つを参照できます。これには、マイクを回転させると変化する -45 などの角度を推測する必要がないという追加の利点があります。
\documentclass[border=0pt]{standalone}
\usepackage{tikz}
\tikzset{
pics/microph/.style={code={
\draw[black, line width=.2em, rounded corners=1.7ex]
(-.85em,4.5ex) -- (-.85em,2ex) -- (.85em,2ex) -- (.85em,4.5ex);
\path (0,2ex) coordinate (-plug);
\fill[black,name prefix ..] % https://tex.stackexchange.com/a/194370
(-.6em,5ex) to[rounded corners=1.2ex]
(-.6em,2.5ex) to[rounded corners=1.2ex] (.6em,2.5ex)
-- (.6em,5ex) to[rounded corners=.2ex] ++(-.85em,0) to[rounded corners=.2ex] ++(0,.35ex) -- ++(.85em,0)
-- (.6em,5.5ex) to[rounded corners=.2ex] ++(-.85em,0) to[rounded corners=.2ex] ++(0,.35ex) -- ++(.85em,0)
-- (.6em,6ex) to[rounded corners=.2ex] ++(-.85em,0) to[rounded corners=.2ex] ++(0,.35ex) -- ++(.85em,0)
-- (.6em,6.5ex) to[rounded corners=.2ex] ++(-.85em,0) to[rounded corners=.2ex] ++(0,.35ex) -- ++(.85em,0)
to[rounded corners=1.2ex]
(.6em,8ex) to[rounded corners=1.2ex]
(-.6em,8ex) to cycle;
}},
}
\begin{document}
\begin{tikzpicture}
\begin{scope}
\clip (-8.5,-6.5) rectangle (8.5,6.5);
\node[fill=cyan, draw=cyan, minimum width=17cm, minimum height=13cm](sky){};
\pic[rotate=40] (microfono) at (4.5,-5) {microph};
\draw[black, line width=2pt] (microfono-plug) -- ++(.2,-.2) -- ++(0,-2);
\end{scope}
\end{tikzpicture}
\end{document}
答え4
私のコメントで述べたように、問題はTikZマニュアルのpic {microph}
最初のpic {seagull}
セクションの定義ではなく、あなたのところで発生しています。これは明らかに、18 Pics: Small Pictures on Paths
バグのソース コード内にありますpic operation
。このバグにより、to
のコード内の操作にpic
互換性がなくなります。
pic
この問題は、 操作を許容しない操作のバグに起因していますto
。これらの操作を に置き換えると--
、動作します。
マニュアルのセクションに示されているように、 を使用すると外部からアクセス可能pic
な場所に配置できるため、ローカル ボックスは必要ありません。そこで、ワイヤが接続される右側、つまりマイクの下部の中央にという座標を追加しました。node
prefix name
18.2 The Pic Syntax
(-milieu)
\draw[black, line width=.2em, rounded corners=1.7ex,pic actions]
(-.85em,4.5ex) -- (-.85em,2ex) -- (.85em,2ex)coordinate[midway](-milieu) -- (.85em,4.5ex);
\documentclass[border=0pt]{standalone}
\usepackage{tikz}
\tikzset{
pics/microph/.style={code={
\draw[black, line width=.2em, rounded corners=1.7ex,pic actions]
(-.85em,4.5ex) -- (-.85em,2ex) -- (.85em,2ex)coordinate[midway](-milieu) -- (.85em,4.5ex);
\fill[black,pic actions]
(-.6em,5ex)[rounded corners=1.2ex] --%
(-.6em,2.5ex)[rounded corners=1.2ex] --%to
(.6em,2.5ex)
-- (.6em,5ex)[rounded corners=.2ex] --%to
++(-.85em,0)[rounded corners=.2ex] --%to
++(0,.35ex) -- ++(.85em,0)
-- (.6em,5.5ex)[rounded corners=.2ex] --%to
++(-.85em,0)[rounded corners=.2ex] --%to
++(0,.35ex) -- ++(.85em,0)
-- (.6em,6ex)[rounded corners=.2ex] --%to
++(-.85em,0)[rounded corners=.2ex] --%to
++(0,.35ex) -- ++(.85em,0)
-- (.6em,6.5ex)[rounded corners=.2ex] --%to
++(-.85em,0)[rounded corners=.2ex] --%to
++(0,.35ex) -- ++(.85em,0)
[rounded corners=1.2ex]--%to
(.6em,8ex) [rounded corners=1.2ex]--%to
(-.6em,8ex) --%to
cycle;
}},
}
\begin{document}
\begin{tikzpicture}
\begin{scope}
\clip (-8.5,-6.5) rectangle (8.5,6.5);
\node[fill=cyan, draw=cyan, minimum width=17cm, minimum height=13cm](sky){};
\pic[rotate=40] (microfono) at (4.5,-5) {microph};
\draw[black, line width=2pt] (microfono-milieu) -- ++(.2,-.2) -- ++(0,-2);
\end{scope}
\end{tikzpicture}
\end{document}