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条回答
合肥-Renascence_5
2020-03-24 09:36 .采纳回答
根据tex stack exchange 上的回答[tex sc](https://tex.stackexchange.com/questions/533786/failed-to-use-the-local-bounding-box-produced-by-foreach-and-pic),需要用到`/.expanded`将`\i`完全展开 ```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/.expanded=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} ```

一周热门 更多>