Estoy intentando generar un diagrama que contenga repetidamente los mismos gráficos. Vea a continuación un gráfico de muestra:
Así lo estoy generando:
\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}
Deseo definir el rectángulo biselado como .pic para poder usarlo más adelante con \path
el comando.
Estoy buscando algo como esto:
\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}
Respuesta1
¿Estás buscando algo así?
\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}
Podrías definir elpic
en este casotambién usando pics/champic/.style={code={\node[mycham] (-node){};}}
. Sin embargo, AFAIK, esta sintaxis es menos flexible. Imagina que quieres pasar más de un argumento a la imagen, como en
\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}
Como puedes ver, con la sintaxis elegida aquí esto no es problema, pero con la /.pic=
sintaxis no sabría cómo hacerlo.
Por supuesto, si no tiene parámetros y está seguro de que nunca los necesitará, puede hacerlo
\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}
como sugieres.