foreach 中 local bounding box 命名的 pic 和 node 无法被 fit

2020-03-23 15:16发布

```tex \documentclass[tikz]{standalone} \usetikzlibrary{fit} \tikzset{% pics/abc/.style={% cod...

```tex \documentclass[tikz]{standalone} \usetikzlibrary{fit} \tikzset{% pics/abc/.style={% code={ \node {this is some path}; } } } \begin{document} \begin{tikzpicture} %fit失败 \foreach \i in {1,...,3} \pic[local bounding box=a\i] at (0,\i) {abc}; \node[draw,fit={(a1)(a2)(a3)}] {}; %fit成功 \pic[local bounding box=a4] at (10,4) {abc}; \pic[local bounding box=a5] at (10,5) {abc}; \pic[local bounding box=a6] at (10,6) {abc}; \node[draw,fit={(a4)(a5)(a6)}] {}; \end{tikzpicture} \end{document} ``` 请问在保留`foreach`语句的条件下,如何让`(a1)(a2)(a3)`成功被`fit`?
3条回答
咸菜的味道
2020-03-24 01:04
```tex \tikzset{ seagull/.pic={ \draw (-3mm,0) to [bend left] (0,0) to [bend left] (3mm,0); } } \tikz{ \foreach \i in {1,2,3}{ \pic [local bounding box={a\i},] at(0,\i) {seagull}; } } \ifcsname pgf@sh@ns@a1\endcsname yes \else no \fi \csname pgf@sh@np@a1\endcsname \meaning\southwest ``` 看一下这段代码的执行结果就知道为什么会 fit 失败了。原因跟 **pgfplotstable** 手册(1.16版)的最后一页的例子一样。 从你的代码看,你可能需要 `current path bounding box` 这个预定义 node.

一周热门 更多>