tikz에서 모따기된 사각형을 .pic으로 정의하는 방법은 무엇입니까?

tikz에서 모따기된 사각형을 .pic으로 정의하는 방법은 무엇입니까?

동일한 그래픽이 반복적으로 포함된 다이어그램을 생성하려고 합니다. 아래 샘플 그래픽을 참조하세요.

여기에 이미지 설명을 입력하세요

이것이 내가 생성하는 방법입니다.

\documentclass[tikz, border=2px]{standalone}
\usetikzlibrary{shapes.misc, shapes.geometric}

\begin{document}
\tikzset{
    line/.style={-, draw=black!30, line width=1pt},
}

\begin{tikzpicture}[node distance=2cm]
    \node[draw=black!30, rectangle, minimum height=8mm, minimum width=8mm,line width=1pt, chamfered rectangle,chamfered rectangle corners={south west, south east},chamfered rectangle xsep=2pt, below] at (0, 0) (b1) {} ;
    \node[draw=black!30, rectangle, minimum height=8mm, minimum width=8mm,line width=1pt, chamfered rectangle,chamfered rectangle corners={south west, south east},chamfered rectangle xsep=2pt, below] at (1, 1) (b2) {} ;
    \node[draw=black!30, rectangle, minimum height=8mm, minimum width=8mm,line width=1pt, chamfered rectangle,chamfered rectangle corners={south west, south east},chamfered rectangle xsep=2pt, below] at (0, 2) (b3) {} ;
    \draw[line] (b1) -- (b2) -- (b3);
\end{tikzpicture}
\end{document}

\path나중에 명령 으로 사용할 수 있도록 모따기된 직사각형을 .pic으로 정의하고 싶습니다 .

나는 다음과 같은 것을 찾고 있습니다 :

\tikzset{
line/.style={-, draw=black!30, line width=1pt},
box/.pic={
    \draw[draw=black!30, rectangle, minimum height=8mm, minimum width=8mm,line width=1pt, chamfered rectangle,chamfered rectangle corners={south west, south east},chamfered rectangle xsep=2pt, below] (0, 0);
    },
}

\begin{tikzpicture}[node distance=2cm]
    \path[line] (0, 0) pic {box} --
                (1, 1) pic {box} --
                (0, 2) pic {box};
\end{tikzpicture}

답변1

이런 것을 찾고 계십니까?

\documentclass[tikz, border=2px]{standalone}
\usetikzlibrary{shapes.misc, shapes.geometric}

\begin{document}
\tikzset{
    line/.style={-, draw=black!30, line width=1pt},
}

\begin{tikzpicture}[mycham/.style={draw=black!30, rectangle, minimum height=8mm,
minimum width=8mm,line width=1pt, chamfered rectangle,chamfered rectangle
corners={south west, south east},chamfered rectangle
xsep=2pt},pics/champic/.style={code={\node[mycham] (-node){};}}]
    \path (0, 0) pic (b1) {champic}
    -- (1, 1) pic (b2){champic} 
    -- (0,2)  pic (b3){champic};
    \draw[line] (b1-node) -- (b2-node) -- (b3-node);
\end{tikzpicture}
\end{document}

여기에 이미지 설명을 입력하세요

당신은pic 이 경우을 사용하기도 합니다 pics/champic/.style={code={\node[mycham] (-node){};}}. 그러나 AFAIK에서는 이 구문의 유연성이 떨어집니다. 다음과 같이 그림에 둘 이상의 인수를 전달하고 싶다고 상상해 보세요.

\documentclass[tikz, border=2px]{standalone}
\usetikzlibrary{shapes.misc, shapes.geometric}

\begin{document}
\tikzset{
    line/.style={-, draw=black!30, line width=1pt},
}

\begin{tikzpicture}[mycham/.style={draw=black!30, rectangle, minimum height=8mm,
minimum width=8mm,line width=1pt, chamfered rectangle,chamfered rectangle
corners={south west, south east},chamfered rectangle
xsep=2pt},pics/champic/.style n args={2}{code={\node[mycham,#2] (-node){#1};}}]
    \path (0, 0) pic (b1) {champic={A}{blue}}
    -- (1, 1) pic (b2){champic={B}{red}} 
    -- (0,2)  pic (b3){champic={C}{green!70!black}};
    \draw[line] (b1-node) -- (b2-node) -- (b3-node);
\end{tikzpicture}
\end{document}

여기에 이미지 설명을 입력하세요

보시다시피, 여기에서 선택한 구문을 사용하면 문제가 되지 않지만 /.pic=구문을 사용하면 어떻게 해야 할지 모르겠습니다.

물론, 매개변수가 없고 매개변수가 전혀 필요하지 않다고 확신하는 경우 다음을 수행할 수 있습니다.

\documentclass[tikz, border=2px]{standalone}
\usetikzlibrary{shapes.misc, shapes.geometric}

\begin{document}
\tikzset{
    line/.style={-, draw=black!30, line width=1pt},
}

\begin{tikzpicture}[mycham/.style={draw=black!30, rectangle, minimum height=8mm,
minimum width=8mm,line width=1pt, chamfered rectangle,chamfered rectangle
corners={south west, south east},chamfered rectangle
xsep=2pt},champic/.pic={\draw (0,0) node[mycham] (-node){};}]
    \path (0, 0) pic (b1) {champic}
    -- (1, 1) pic (b2){champic} 
    -- (0,2)  pic (b3){champic};
    \draw[line] (b1-node) -- (b2-node) -- (b3-node);
\end{tikzpicture}
\end{document}

당신이 제안한대로.

관련 정보