5

This is a very simple question.

Is it possible to add a "curve" effect to a node?

Consider a simple rectangle node:

\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\node[draw,minimum width=3cm,minimum height=2cm]{};
\end{tikzpicture}
\end{document}

I'd like to curve it like the following image

enter image description here

This should be applicable to all node shapes.

Mason
  • 195
  • What will happen to the text content of the node? Are they curved too? –  Sep 28 '14 at 15:10
  • @HarishKumar I was thinking about nodes filled with color and not text, so I don't have a specific requirement – Mason Sep 28 '14 at 15:23
  • So they won't have text inside? –  Sep 28 '14 at 15:25
  • When you say that it should be applicable to all node shapes, I don't really understand. That node is deformed, if you like, in a specific way. How would that deformation apply to, say, a triangle or an octagon? What about a star? – cfr Sep 28 '14 at 15:33
  • I'd like that the text was also curved. – skpblack Sep 28 '14 at 15:39
  • @cfr what I have in mind is something like to bend to option for paths. As that option curves a path, I'd like to have the ability to curve a node. – Mason Sep 28 '14 at 17:01
  • @HarishKumar no, they wont. – Mason Sep 28 '14 at 17:01
  • Why don't you simply draw it especially if you don't have text? Why do you need nodes? – percusse Sep 28 '14 at 17:18

1 Answers1

5

This is one possible solution via tikz pics. Here a marco called mynode is defined with 6 arguments that is equipped with different x, y lengths and curvatures. The the last one is for text label with curve. If there is no text at all, remove the path decoration in the code.

The same idea can be applied to other shapes, say, triangle, but the code may need some modifications. What follows are the definitions of arguments

#1=color, #2=x length, #3=y height, #4=inward bend angle, #5=outward bend angle, #6=text

enter image description here

Code

\documentclass[border=10pt]{standalone}%{article}
\usepackage{tikz}
\usetikzlibrary{decorations.pathmorphing}
\usetikzlibrary{decorations.text}
\tikzset{%
pics/.cd,
mynode/.style args={#1#2#3#4#5#6}{
code={\node[inner sep=0pt,outer sep=0pt] at (0,0) (a) {};
\path[fill=#1] 
(a) to[bend right=#4] ++(#2,0) -- ++(0,#3) to[bend left=#5] ++(-#2,0) -- cycle;
\path[postaction={decorate},           % remove this path if no text decoration.
         decoration={raise=-15pt,
         text along path, text={#6},
         text align={left indent ={1cm}}}] 
(a) to[bend right=#4] ++(#2,0); 
}},
}

% #1=color, #2=x length, #3=y height, #4= inward bend  angle, #5= outward bend angle, #6=text

\begin{document}
\begin{tikzpicture}
  \pic {mynode={purple}{6cm}{-1cm}{20}{10}{This is my curved text.}};
  \pic at (0,-2) {mynode={olive}{6cm}{-2cm}{30}{20}{This is my curved text.}};
  \pic at (0,-5) {mynode={blue}{6cm}{-2cm}{40}{30}{This is my curved text.}};
\end{tikzpicture}
\end{document}
Jesse
  • 29,686