1

I need to draw a rectangle with rounded angles and with an arrow in the middle of each side. Googling, I found this code to get a "mid arrow", but it gives me back an error ("Dimension too large [...]") when I start debugging

\documentclass[tikz,border=3mm]{standalone}
\usetikzlibrary{decorations.pathreplacing,decorations.markings}

\tikzset{
% style to apply some styles to each segment of a path
on each segment/.style={
    decorate,
    decoration={
        show path construction,
        moveto code={},
        lineto code={
            \path [#1]
            (\tikzinputsegmentfirst) -- (\tikzinputsegmentlast);
        },
        curveto code={
            \path [#1] (\tikzinputsegmentfirst)
            .. controls
            (\tikzinputsegmentsupporta) and (\tikzinputsegmentsupportb)
            ..
            (\tikzinputsegmentlast);
        },
        closepath code={
            \path [#1]
            (\tikzinputsegmentfirst) -- (\tikzinputsegmentlast);
        },
    },
},
% style to add an arrow in the middle of a path
mid arrow/.style={postaction={decorate,decoration={
            markings,
            mark=at position .5 with {\arrow[#1]{stealth}}
}}},
}

\begin{document}    
\begin{tikzpicture}
    \draw [thick, rounded corners=2pt, postaction={on each segment={mid 
    arrow=black}}] (0.1,0.1) -- (0.1,0.9) -- (0.9,0.9) -- (0.9,0.1) -- cycle;
\end{tikzpicture}
\end{document}

I managed to fix the problem just by increasing the size of the rectangle (I striclty need the dimensions to be those). Another problem is that in the final picture I get arrows on the corner too like this

enter image description here

I just want to obtain a rectangle like one of these

enter image description here enter image description here

Thanks for help!

0

The problem is that you add the arrow to all segments. You may want to add it only to the straight ones.

\documentclass[tikz,border=3mm]{standalone}
\usetikzlibrary{decorations.pathreplacing,decorations.markings}
\newcounter{flipflop}
\tikzset{
% style to apply some styles to each segment of a path
on each straight segment/.style={
    decorate,
    decoration={
        show path construction,
        moveto code={},
        lineto code={
            \path [#1]
            (\tikzinputsegmentfirst) -- (\tikzinputsegmentlast);
        },
        curveto code={
            \path  (\tikzinputsegmentfirst)
            .. controls
            (\tikzinputsegmentsupporta) and (\tikzinputsegmentsupportb)
            ..
            (\tikzinputsegmentlast);
        },
        closepath code={
            \path 
            (\tikzinputsegmentfirst) -- (\tikzinputsegmentlast);
        },
    },
},
set flipflop/.code=\setcounter{flipflop}{#1},
on each other straight segment/.style={
    decorate,
    decoration={
        show path construction,
        moveto code={},
        lineto code={\stepcounter{flipflop}
            \path \ifodd\value{flipflop} [#1]\fi
            (\tikzinputsegmentfirst) -- (\tikzinputsegmentlast);
        },
        curveto code={
            \path  (\tikzinputsegmentfirst)
            .. controls
            (\tikzinputsegmentsupporta) and (\tikzinputsegmentsupportb)
            ..
            (\tikzinputsegmentlast);
        },
        closepath code={
            \path 
            (\tikzinputsegmentfirst) -- (\tikzinputsegmentlast);
        },
    },
},
% style to add an arrow in the middle of a path
mid arrow/.style={postaction={decorate,decoration={
            markings,
            mark=at position .5 with {\arrow[#1]{stealth}}
}}},
}

\begin{document}    
\begin{tikzpicture}
    \draw [thick, rounded corners=2pt, postaction={on each straight segment={mid 
    arrow=black}}] (0.1,0.1) -- (0.1,0.9) -- (0.9,0.9) -- (0.9,0.1) -- cycle;
  \begin{scope}[xshift=1.5cm]
    \draw [thick, rounded corners=2pt, postaction={set flipflop=0,on each other straight segment={mid 
    arrow=black}}] (0.1,0.1) -- (0.1,0.9) -- (0.9,0.9) -- (0.9,0.1) -- cycle;
  \end{scope}
  \begin{scope}[xshift=3cm]
    \draw [thick, rounded corners=2pt, postaction={set flipflop=1,on each other straight segment={mid 
    arrow=black}}] (0.1,0.1) -- (0.1,0.9) -- (0.9,0.9) -- (0.9,0.1) -- cycle;
  \end{scope}
\end{tikzpicture}
\end{document}

enter image description here

0

One more suggestion:

\documentclass{book}
\usepackage{tikz}
\usetikzlibrary{shapes.arrows}
\tikzset{
myarrow/.style={
  draw,thick,
  single arrow,
  text width=16pt,
%  fill=white
  },
}

\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};
\end{tikzpicture}

\vspace{2pc}

 \begin{tikzpicture}
   \node [draw,rectangle,minimum size=8pc](r){};
   \node[myarrow,rotate=90] at (r.west){};
   \node[myarrow] at (r.north){};
 \end{tikzpicture}%

\end{document}

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.