10

I'm trying to recreate this figure, but unfortunately I no longer have access to its source material:

original

So far I've figured out how to draw the rectangle:

\documentclass{standalone}   

\usepackage{tikz}
\usetikzlibrary{shapes.misc}

\definecolor{viewbutton_border}{RGB}{113, 145, 203}
\definecolor{viewbutton_top}{RGB}{143, 171, 217}
\definecolor{viewbutton_bottom}{RGB}{115, 147, 204}

\begin{document}
\begin{tikzpicture}
    \node (button) at (0,0) [
        rectangle,
        top color=viewbutton_top, 
        bottom color=viewbutton_bottom,
        draw=viewbutton_border, 
        rounded corners=0.5mm, 
        line width=0.4mm,
        minimum width=1.72cm,
        minimum height=1.37cm,
    ] {};
    % how to draw the arrows?
\end{tikzpicture}
\end{document}

mwe

And now I'm lost figuring out how to draw these arrows with TikZ inside the rectangle. Do you have any suggestions?

17

The basic idea is to use a path picture to draw the arrows over the background of the node. Inside the path picture a special node path picture bounding box is available which is a rectangle which covers the extent of the node path.

The calc library is used to calculate start and end points points along the diagonals from the center of the path picture bounding box to each of its corners and also to calculate the height and width of the node. The minimum of the height and width is used as a basis for the thickness of the line and the dimensions of the arrowhead. Then the arrow is drawn using the Triangle arrow tip from the arrows.meta library.

I have also assumed that the border of the button should scale with the size of the button, which is passed as a parameter to the view button style.

\documentclass[border=5]{standalone}
\usepackage{tikz}
\usetikzlibrary{arrows.meta,calc,positioning}
\definecolor{vbborder}{RGB}{93, 120, 190}
\definecolor{vbtop}{RGB}{143, 171, 217}
\definecolor{vbbottom}{RGB}{115, 147, 204}
\tikzset{view button/.style={
  shape=rectangle,  
  minimum width={#1}, minimum height={(#1)*1.37/1.72},
  line width={(#1)/20}, rounded corners={(#1)/5},
  top color=vbtop, 
  bottom color=vbbottom, 
  draw=vbborder,
  path picture={
    \foreach \i in {45,135,225,315}
      \draw let \p1=(path picture bounding box.center),
        \p2=(path picture bounding box.\i),
        \n1={min(abs(\x2-\x1),abs(\y2-\y1))} in
        [white, line width=\n1/4, -{Triangle[width=\n1*.75,length=\n1*.375]}]
        ($(\p1)!0.175!(\p2)$) -- ($(\p1)!0.7!(\p2)$);
}},
view button/.default=1cm}
\begin{document}
\begin{tikzpicture}
\coordinate (v);
\foreach \i in {1,...,5}
  \node [view button=\i*10pt, above=5pt of v] (v) {};
\end{tikzpicture}
\end{document}

enter image description here

  • This is very impressive and uses many techniques that I'm unfamiliar with. Would you care to explain the general principle? I see some control flow and use of path picture... how does it work? – Korijn Dec 31 '16 at 15:29
  • 1
    @Korijn see the updated answer. – Mark Wibrow Dec 31 '16 at 16:39
  • This answer taught me a lot about Tikz, and solved the problem perfectly, retaining the background gradient. Thanks. – Korijn Jan 1 '17 at 21:30
11

I draw some squares like this. First, the background blue rectangle. Above that, a white square. On top of that, four squares, tilted at 45°, so that their tips will fall on the x or y axis. Last a blue square in the middle it.

\documentclass[a4paper,landscape,10pt]{article}
\usepackage{tikz}

\definecolor{bborder}{RGB}{113, 145, 203}
\definecolor{bbottom}{RGB}{115, 147, 204}
\definecolor{btop}{RGB}{255, 255, 255}

\pagestyle{empty}
\begin{document}
\begin{tikzpicture}
  % Draw the outer blue rectangle/square
  \draw[ultra thick, rounded corners, draw=bborder, fill=bbottom]
  (-10,-8.1) -- (-10,8.1) -- (10,8.1) -- (10,-8.1);
  % Draw the white square
  \draw[fill=btop,draw=btop]
  (-6.3,-6.3) -- (-6.3,6.3) -- (6.3,6.3) -- (6.3,-6.3) -- cycle;
  % Draw four squares, each tilted at 45° filled in blue
  \draw[draw=bbottom, fill=bbottom]
  (0,-7.9) -- (-3.1,-4.8) -- (0,-1.7) -- (3.1,-4.8) -- cycle;
  \draw[draw=bbottom, fill=bbottom]
  (0,7.9) -- (-3.1,4.8) -- (0,1.7) -- (3.1,4.8) -- cycle;
  \draw[draw=bbottom, fill=bbottom]
  (-7.9,0) -- (-4.8,-3.1) -- (-1.7,0) -- (-4.8,3.1) -- cycle;
  \draw[draw=bbottom, fill=bbottom]
  (7.9,0) -- (4.8,-3.1) -- (1.7,0) -- (4.8,3.1) -- cycle;
  % A last square on top in the middle, again in blue
  \draw[draw=bbottom,fill=bbottom]
  (-2.5,0) -- (0,-2.5) -- (2.5,0) -- (0,2.5);
\end{tikzpicture}
\end{document}

This is my result. Please, polish my code to your needs.

enter image description here

  • Nice out-of-the-box thinking! Unfortunately, I really want the gradient in the background to remain visible and I'm not sure how I would accomplish that with this approach. It looks very pretty though! – Korijn Dec 31 '16 at 15:32
  • 1
    @Korijn: Oh yes. You are right. Bear with me, this was my second attempt on TkiZ. It was a good learning experience. – Jan Dec 31 '16 at 18:32
11

A short code with pstricks, compilable with pdflatex if you add the switch --enable-write18 for MiKTeX, or -shell-escape for TeX Live and MacTeX:

\documentclass[x11names, border=3pt]{standalone}
\usepackage{pstricks-add}
\usepackage{auto-pst-pdf}

\newcommand\BigArrow{%
\psset{unit=1mm, linecolor=white, linejoin=1}%
\pnode(13,0){S}
\pnodes{A}(0,2)(8,2)(8,5)
\pnodes{B}(0,-2)(8,-2)(8,-5)
\pspolygon[fillstyle=solid](A0)(A1)(A2)(S)(B2)(B1)(B0)}%

\begin{document}

\begin{pspicture}
\psframe[unit=2cm, linewidth=3pt, linecolor=SteelBlue3, fillstyle=solid, fillcolor=LightSteelBlue3, framearc=0.1](-1,-1)(1,1)%
\multido{\i = 45 + 90}{4}{\rput{\i}(0.4; \i) {\BigArrow}}
\end{pspicture}

\end{document}

enter image description here

  • If possible I would prefer to stick with utilities that are "available by default". It's easier to deploy in automated systems. I'm also unfamiliar with pstrick so a Tikz solution would be preferable to me. – Korijn Dec 31 '16 at 15:34
  • 1
    The switch is necessary only if you compile with pdflatex. Otherwise, you can remove loading of auto-pst-pdf, and either: – follow the classic latex->dvips->pstopdf way, or – compile with xelatex. – Bernard Dec 31 '16 at 15:39

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.