2

How can I draw this shape with tikz?

display shape

4
  • The are many different ways. Technically, "shape" refers to a typle of node and use \pgfdeclareshape on page 1034 of the TikZ manual, although I doubt that is what you want. Apr 23, 2018 at 20:56
  • 2
    Possibly related tex.stackexchange.com/questions/366802
    – user30471
    Apr 23, 2018 at 21:32
  • Do you just want to draw this figure, or declare a "new" shape? And why did you tag your question tikz-styles?
    – user121799
    Apr 23, 2018 at 21:48
  • My question was not precise -- actually I wanted to ask how to declare the shape! Apr 26, 2018 at 5:45

2 Answers 2

3

This is a solution using pgfdeclareshape to the shape display

\documentclass[tikz, border = 5pt]{standalone}

\usetikzlibrary{shapes}
\usetikzlibrary{arrows}
\usetikzlibrary{positioning}

\makeatletter

\pgfdeclareshape{display}
{
  \inheritsavedanchors[from=rectangle] % this is nearly a rectangle
  \inheritanchorborder[from=rectangle]
  \inheritanchor[from=rectangle]{north}
  \inheritanchor[from=rectangle]{west}
  \inheritanchor[from=rectangle]{east}
  \inheritanchor[from=rectangle]{south}
  \inheritanchor[from=rectangle]{center}
  \inheritbackgroundpath[from=rectangle]
  \backgroundpath{
    % points
    \southwest \pgf@xa=\pgf@x \pgf@ya=\pgf@y
    \northeast \pgf@xb=\pgf@x \pgf@yb=\pgf@y
    % dimensions
    \pgfmathsetlength{\pgfutil@tempdima}{\pgf@xb-\pgf@xa}
    \pgfmathsetlength{\pgfutil@tempdimb}{\pgf@yb-\pgf@ya}
    % path
    \pgfpathmoveto{\pgfpointadd{\pgfqpoint{\pgf@xa}{\pgf@ya}}{\pgfqpoint{0.2\pgfutil@tempdima}{0pt}}}
    \pgfpathlineto{\pgfpointadd{\pgfqpoint{\pgf@xa}{\pgf@ya}}{\pgfqpoint{0pt}{0.5\pgfutil@tempdimb}}}
    \pgfpathlineto{\pgfpointadd{\pgfqpoint{\pgf@xa}{\pgf@yb}}{\pgfqpoint{0.2\pgfutil@tempdima}{0pt}}}    
    \pgfpathlineto{\pgfpointadd{\pgfqpoint{\pgf@xb}{\pgf@yb}}{\pgfqpoint{-0.2\pgfutil@tempdima}{0pt}}}
    \pgfpatharc{90}{-90}{0.2\pgfutil@tempdima and 0.5\pgfutil@tempdimb}
    \pgfpathlineto{\pgfpointadd{\pgfqpoint{\pgf@xb}{\pgf@ya}}{\pgfqpoint{-0.2\pgfutil@tempdima}{0pt}}}
    \pgfpathlineto{\pgfpointadd{\pgfqpoint{\pgf@xa}{\pgf@ya}}{\pgfqpoint{0.2\pgfutil@tempdima}{0pt}}}
    \pgfpathclose    
  }
}


\makeatother

\tikzstyle{decision} = [diamond, draw, fill=blue!20, 
text width = 4.5em, text badly centered, node distance = 3cm, inner sep = 0pt]
\tikzstyle{block} = [rectangle, draw, fill = blue!20, 
text width = 5em, text centered, rounded corners, minimum height = 4em]
\tikzstyle{line} = [draw, -latex']
\tikzstyle{disp} = [display, draw, fill = cyan!20, 
text width = 5em, text centered, minimum height = 4em]



\begin{document}

\begin{tikzpicture}[node distance = 4cm, auto]  
  % nodes
  \node [block] (init) {Think of picture};
  \node [disp, right of = init] (display) {Draw picture};
  \node [decision, below of = init] (question) {Did they guess it?};
  \node [block, right of = question] (no) {Point repeteadly to the same picture};
  \node [block, left of = question] (yes) {You win!};
  % edges
  \path [line] (init) -- (display);
  \path [line] (init) -- (question);
  \path [line] (question) -- (no) node[midway, fill = white]{No};
  \path [line] (question) -- (yes) node[midway, fill = white, above]{Yes};
  \path [line] (no.south) -- ++(0, -1cm) -| (question.south);
  %
  \node[above = 0.5cm of init] {How to play Pictionary};
\end{tikzpicture}


\end{document}

enter image description here

0
1

Addendum: Adding rounded corners shows some unwanted effects:

rounded corners

The issue can be solved by removing the last two pathlines from the declareshape block:

\pgfdeclareshape{display}
{
  \inheritsavedanchors[from=rectangle] % this is nearly a rectangle
  \inheritanchorborder[from=rectangle]
  \inheritanchor[from=rectangle]{north}
  \inheritanchor[from=rectangle]{west}
  \inheritanchor[from=rectangle]{east}
  \inheritanchor[from=rectangle]{south}
  \inheritanchor[from=rectangle]{center}
  \inheritbackgroundpath[from=rectangle]
  \backgroundpath{
    % points
    \southwest \pgf@xa=\pgf@x \pgf@ya=\pgf@y
    \northeast \pgf@xb=\pgf@x \pgf@yb=\pgf@y
    % dimensions
    \pgfmathsetlength{\pgfutil@tempdima}{\pgf@xb-\pgf@xa}
    \pgfmathsetlength{\pgfutil@tempdimb}{\pgf@yb-\pgf@ya}
    % path
    \pgfpathmoveto{\pgfpointadd{\pgfqpoint{\pgf@xa}{\pgf@ya}}{\pgfqpoint{0.2\pgfutil@tempdima}{0pt}}}
    \pgfpathlineto{\pgfpointadd{\pgfqpoint{\pgf@xa}{\pgf@ya}}{\pgfqpoint{0pt}{0.5\pgfutil@tempdimb}}}
    \pgfpathlineto{\pgfpointadd{\pgfqpoint{\pgf@xa}{\pgf@yb}}{\pgfqpoint{0.2\pgfutil@tempdima}{0pt}}}    
    \pgfpathlineto{\pgfpointadd{\pgfqpoint{\pgf@xb}{\pgf@yb}}{\pgfqpoint{-0.2\pgfutil@tempdima}{0pt}}}
    \pgfpatharc{90}{-90}{0.25\pgfutil@tempdima and 0.5\pgfutil@tempdimb}
    %\pgfpathlineto{\pgfpointadd{\pgfqpoint{\pgf@xb}{\pgf@ya}}{\pgfqpoint{-0.2\pgfutil@tempdima}{0pt}}}
    %\pgfpathlineto{\pgfpointadd{\pgfqpoint{\pgf@xa}{\pgf@ya}}{\pgfqpoint{0.2\pgfutil@tempdima}{0pt}}}
    \pgfpathclose    
  }
}

\tikzstyle{disp} = [display, draw, fill = cyan!20, 
text width = 5em, text centered, minimum height = 4em, rounded corners=2pt]

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .