# How to create a rectangle tikzstyle with arrows as edges/borders?

is it possible to create a new rectangle tikzstyle with arrows arround it? Like this...

Thank you

• Welcome to TeX.SX. Questions about how to draw specific graphics that just post an image of the desired result are really not reasonable questions to ask on the site. Please post a minimal compilable document showing that you've tried to produce the image and then people will be happy to help you with any specific problems you may have. See minimal working example (MWE) for what needs to go into such a document. – Stefan Pinnow Dec 9 '18 at 14:32

with append after command you can define "new" box shape with arrow:

    \documentclass[tikz, margin=3mm]{standalone}
\usetikzlibrary{arrows.meta}

\begin{document}
\begin{tikzpicture}[
arrowsbox/.style = {text width=#1, align=center, inner sep=2mm,
append after command={\pgfextra{\let\LN\tikzlastnode
\draw[thick, -Triangle, shorten >=2mm, shorten <=1mm]
(\LN.north west) edge (\LN.north east)
(\LN.north east) edge (\LN.south east)
(\LN.south east) edge (\LN.south west)
(\LN.south west)  to  (\LN.north west);}
}
}% end of arrowsbox style
]
\node[arrowsbox=44mm] {some text\\some text\\[1ex] some test\\some text};
\end{tikzpicture}
\end{document}


• On p. 162 the pgfmanual says about \pgfextra: "Note that this operation should only be used by real experts and should only be used deep inside clever macros, not on normal paths." Indeed, I have seen it gone wrong. So please try to write a solution that does not make use of it. – marmot Dec 9 '18 at 14:01
• Dear @marmot, thank you very much for warning. So far i haven't any bad experiences with similar solutions. So i will be very glad if you show me (maybe in chat room), when in where i will be in trouble with my solution. this is good to know. btw, i know for warning in manual which you cite :-) – Zarko Dec 9 '18 at 18:14
• Isn't this here an example of this sort? – marmot Dec 9 '18 at 22:46
• @marmot, thank you very much. but in this particular case there is no rotating (around of center of node). hopefully ... – Zarko Dec 9 '18 at 22:51
• It really is not tied to rotations. Rather, it is a problem with pgfkeys. As you know, they are local and inherited by the full path. However, with your construction you precisely undermine the whole structure. To see what I mean, try e.g. \node[arrowsbox=44mm,red] .... If that was an "ordinary" style, the arrows would turn red. With your style they don't. Yes, you can fix this by passing an argument to the arrows. However, this would make this style very different in behavior than any of the standard styles. – marmot Dec 9 '18 at 22:57

One way is to use arrows to draw around a rectangular node.

\documentclass[border=3mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{arrows}
\tikzset{arw/.style={-triangle 60,line width=1pt,shorten <= 4pt}}
\begin{document}
\begin{tikzpicture}
\node[text width=3cm,align=center,name=rect] at (0,0) {\textbf{For each design} \\ this.. \\ $\alpha=\beta$};
\draw[arw] (rect.south west) -- (rect.north west);
\draw[arw] (rect.north west) -- (rect.north east);
\draw[arw] (rect.north east) -- (rect.south east);
\draw[arw] (rect.south east) -- (rect.south west);
\end{tikzpicture}
\end{document}

• Your answer is OK, but I would create a pic with your arrowed rectangle, in order not to have to re-write all the \draws every time. – CarLaTeX Dec 9 '18 at 13:52

A node style arrowed which uses path picture to draw the arrows.

\documentclass[tikz,border=3.14mm]{standalone}
\begin{document}
\begin{tikzpicture}[arrowed/.style={inner sep=6pt,path picture={
\draw[-latex,#1] ([xshift=2pt,yshift=-2pt]path picture bounding box.north west)
-- ([xshift=-2pt,yshift=-2pt]path picture bounding box.north east);
\draw[-latex,#1] ([xshift=-2pt,yshift=-2pt]path picture bounding box.north east)
-- ([xshift=-2pt,yshift=2pt]path picture bounding box.south east);
\draw[-latex,#1] ([xshift=-2pt,yshift=2pt]path picture bounding box.south east)
-- ([xshift=2pt,yshift=2pt]path picture bounding box.south west);
\draw[-latex,#1] ([xshift=2pt,yshift=-2pt]path picture bounding box.north west)
-- ([xshift=-2pt,yshift=-2pt]path picture bounding box.north east);
\draw[-latex,#1] ([xshift=2pt,yshift=2pt]path picture bounding box.south west)
-- ([xshift=2pt,yshift=-2pt]path picture bounding box.north west);
}}]
\node[arrowed] at (0,0) {some text};
\node[arrowed={thick,-stealth}] at (3,0) {some more text};
\node[arrowed={thick,stealth-,shorten >=1pt}] at (6,0) {even more text};
\node[anchor=north,arrowed={thick,-stealth,shorten >=1pt},inner sep=10pt,
align=center] at (3,-1)
{\textbf{\emph{For each design choice:}}\\[2mm]
1 -- do something\\ really cool and\\ smart\\[1mm]
2 -- make sure that\\ hibernation time\\ is over
};
\end{tikzpicture}
\end{document}


Just for fun: a version of Zarko's answer but without \pgfextra. Why do I care about \pgfextra? Because on p. 162 the pgfmanual says about \pgfextra: "Note that this operation should only be used by real experts and should only be used deep inside clever macros, not on normal paths." It is really easy to get rid of the \pgfextra. It is certainly not needed for append after command.

\documentclass[tikz,border=3.14mm]{standalone}
\begin{document}
\begin{tikzpicture}[my arrow/.style={thick, -latex, shorten >=2mm,
shorten <=1mm},
arrowsbox/.style = { align=center, inner sep=2mm,
append after command={[every edge/.append style={my arrow,#1}]
(\tikzlastnode.north west) edge (\tikzlastnode.north east)
(\tikzlastnode.north east) edge (\tikzlastnode.south east)
(\tikzlastnode.south east) edge (\tikzlastnode.south west)
(\tikzlastnode.south west) edge  (\tikzlastnode.north west)
}
}
]
\node[arrowsbox={red},inner sep=10pt,blue] {\textbf{\emph{For each design choice:}}\\[2mm]
1 -- do something\\ really cool and\\ smart\\[1mm]
2 -- make sure that\\ hibernation time\\ is over};
\end{tikzpicture}
\end{document}