我的一幅(复杂)图像的基础是由一组坐标确定的面积:
由于我将这个坐标用于进一步的图像构建,所以我喜欢在绘图阶段用 标记它们pin=<...>:<coordinate name>
。在坐标上添加图钉后,区域填充变得很奇怪:
我可以通过首先确定坐标然后绘制轮廓来消除这个问题,但这使我的绘图过程变得复杂:-(。还有其他(简单的)方法可以消除填充区域的这种“干扰”吗?
\documentclass[tikz, margin=3mm]{standalone}
\usetikzlibrary{positioning}
\begin{document}
\begin{tikzpicture}
\coordinate[pin=120:A1] (A1) at ( 0, 0.0);
\coordinate[pin= 60:A2,below right=5.6 and 14 of A1] (A2);
\coordinate[pin=240:A3,below=12 of A1] (A3);
% grid
\draw[blue!25,dashed,thin] (A1) grid[step=1] + (14,-12);
\draw[blue!50,thin] (A1) grid[step=2] + (14,-12);
% podboj (surovec)
\draw[fill=brown!30, fill opacity=0.5, draw opacity=1, thick]
(A1) -| ++ ( 6.0,-1.6) coordinate (sa)
-- ++ ( 2.8, 0.0) coordinate (sb)
-| ++ ( 3.2,-1.6) coordinate (sc)
-- ++ ( 0.0,-0.8) coordinate (sd)
-| (A2)
|- ++ (-1.0,-1.4) coordinate (x)
|- ++ (-4.4,-5.0) coordinate (se)
|- ++ (-6.0, 2.0) coordinate (sf)
|- (A3) -- (A1);
\end{tikzpicture}
\begin{tikzpicture}
\coordinate[pin=120:A1] (A1) at ( 0, 0.0);
\coordinate[pin= 60:A2,below right=5.6 and 14 of A1] (A2);
\coordinate[pin=240:A3,below=12 of A1] (A3);
% grid
\draw[blue!25,dashed,thin] (A1) grid[step=1] + (14,-12);
\draw[blue!50,thin] (A1) grid[step=2] + (14,-12);
% podboj (surovec)
\draw[fill=brown!30, fill opacity=0.5, draw opacity=1, thick]
(A1) -| ++ ( 6.0,-1.6) coordinate[pin=60:sa] (sa)
-- ++ ( 2.8, 0.0) coordinate[pin=60:sb] (sb)
-| ++ ( 3.2,-1.6) coordinate[pin=60:sc] (sc)
-- ++ ( 0.0,-0.8) coordinate[pin=60:sd] (sd)
-| (A2)
|- ++ (-1.0,-1.4) coordinate[pin=300:x] (x)
|- ++ (-4.4,-5.0) coordinate[pin=240:se] (se)
|- ++ (-6.0, 2.0) coordinate[pin= 60:sf] (sf)
|- (A3) -- (A1);
\draw[dashed,red,thick]
(sb) |- (sc);
\end{tikzpicture}
\end{document}
附录:
如果有人感兴趣的话……
我广泛测试了提供的解决方案马克·维布罗(见下面他的回答)。在所有测试中我都没有注意到任何副作用。在测试中我以以下方式使用他的解决方案:
- 在序言中我补充
\makeatletter
\tikzset{make append after command safe/.style={/tikz/append after command/.code=%
\expandafter\def\expandafter\tikz@after@path\expandafter{%
\tikz@after@path\pgfextra{\pgfinterruptpath\path##1;\endpgfinterruptpath}}},
every label/.append style = {align=center},
every pin/.append style = {make append after command safe,
pin distance=7mm, pin edge={blue,solid},
text opacity=1 % for cases, if underlying drawings are (semi)transparent
},
- 按照
tikzpicture
通常的方式使用带引脚的坐标:
\draw[fill=brown!30, fill opacity=0.5, draw opacity=1, thick]
(A1) -| ++ ( 6.0,-1.6) coordinate (sa)
-- ++ ( 2.8, 0.0) coordinate (sb)
-| ++ ( 3.2,-1.6) coordinate (sc)
-- ++ ( 0.0,-0.8) coordinate (sd)
-| (A2)
|- ++ (-1.0,-1.4) coordinate (x)
|- ++ (-4.4,-5.0) coordinate (se)
|- ++ (-6.0, 2.0) coordinate (sf)
|- (A3) -- (A1);
答案1
经过一番挖掘,我们发现 pin 选项的使用append after command
似乎无法保护任何现有路径。
这种方法可能有充分的理由,但在这种情况下(可能会对其他代码产生副作用),一种解决方法是重新定义密钥append after command
以使用 保护路径\pgfinterruptpath...\endpgfinterruptpath
。以下解决方案/解决方法将此重新定义放在另一个密钥内,以便可以在范围或单个路径内使用它:
\documentclass[tikz, margin=5]{standalone}
\usetikzlibrary{positioning}
\makeatletter
\tikzset{make append after command safe/.style={/tikz/append after command/.code=%
\expandafter\def\expandafter\tikz@after@path\expandafter{%
\tikz@after@path\pgfextra{\pgfinterruptpath\path##1;\endpgfinterruptpath}}}}
\makeatother
\begin{document}
\begin{tikzpicture}
\coordinate[pin=120:A1] (A1) at ( 0, 0.0);
\coordinate[pin= 60:A2,below right=5.6 and 14 of A1] (A2);
\coordinate[pin=240:A3,below=12 of A1] (A3);
\draw[blue!25,dashed,thin] (A1) grid[step=1] + (14,-12);
\draw[blue!50,thin] (A1) grid[step=2] + (14,-12);
% podboj (surovec)
\draw[make append after command safe,
fill=brown!30, fill opacity=0.5, draw opacity=1, thick]
(A1) -| ++ ( 6.0,-1.6) coordinate[pin=60:sa] (sa)
-- ++ ( 2.8, 0.0) coordinate[pin=60:sb] (sb)
-| ++ ( 3.2,-1.6) coordinate[pin=60:sc] (sc)
-- ++ ( 0.0,-0.8) coordinate[pin=60:sd] (sd)
-| (A2)
|- ++ (-1.0,-1.4) coordinate[pin=300:x] (x)
|- ++ (-4.4,-5.0) coordinate[pin=240:se] (se)
|- ++ (-6.0, 2.0) coordinate[pin= 60:sf] (sf)
|- (A3) -- (A1);
\draw[dashed,red,thick] (sb) |- (sc);
\end{tikzpicture}
\end{document}