# Custom, space-saving ellipse as TikZ node shape?

in some applications, one wants to use ellipses as node shapes in figures, e.g., when in the literature on a subject typically uses ellipses to denote certain things in figures. The problems with normal ellipses is that they often waste a lot of space:

When a figure is already very wide, then the large "end caps" at the left and right ends of the ellipse can be very annoying, as they consume some space. It would be nice if there was another node shape type that is still round, but more space saving. With flatter end caps, an ellipse around some text can have some lower width:

The first of these ellipses is still a normal one, but the other ones are "morphed" a bit. They are still recognizable as ellipses, though (although they strictly speaking aren't).

The process of building custom node shapes for this is a bit over my head, especially since the math that would be involved for computing the correct boundaries for some node context is probably complicated to do in Tikz.

Here is the Python code that I used for constructing these examples: one can see that using an exponential function does the trick. But for using the node shape in practice, it's probably a bit more important to have the functionality of drawing such shapes in LaTeX itself.

#!/usr/bin/python
import math

def moreimpact(x,base):
if x<0:
return -math.pow(-x,base)
else:
return math.pow(x,base)

print "\\documentclass{article}"
print "\\usepackage{tikz}"
print "\\usetikzlibrary{shapes}"
print "\\begin{document}"
print "\\begin{tikzpicture}"
print "\\node[draw,shape=ellipse,inner sep=1pt] (f1) at (0,2) {This is a long text that leads to a very large ellipse};"

for j in xrange(0,4):
print "\\draw",
for i in xrange(0,360):
if i!=0:
print " -- ",
xpos = math.cos(i/180.0*math.pi)
ypos = math.sin(i/180.0*math.pi)
print "(%f,%f)" % (5*moreimpact(xpos,1.0-0.1*j),0.3*moreimpact(ypos,1.0-0.1*j)-j*1.2),
print " -- cycle;"
print "\\end{tikzpicture}"
print "\\end{document}"


Does anyone know how to define a new node shape for such a "compressed ellipse" or something similar in TikZ (optimally parametrized by what I called "impact" in the code above)? The answer is probably helpful for many people, as I think that this node shape is quite useful in situations in which there is little space for a figure (e.g., presentations), and rectangles or rectangles with rounded corners are already taken for denoting something different.

EDIT: Qrrbrbirlbel provided a link to a post about a "superellipse", which contains some code for a new TikZ node shape called "superellipse". This is precisely what has been asked for. It's just a pity that the size computation doesn't really work:

\node[shape=superellipse,superellipse parameter=3] at (2,3) {This is a long text that leads to a very large ellipse};


This can be worked around by adding negative spaces, but it's just a workaround.

-
Welcome to TeX.sx! Usually, we don't put a greeting or a "thank you" in our posts. While this might seem strange at first, it is not a sign of lack of politeness, but rather part of our trying to keep everything very concise. Accepting and upvoting answers is the preferred way here to say "thank you" to users who helped you. –  hpesoj626 Apr 5 '13 at 4:24
That is one interesting question. You might convert that function into a shape (What are its parameters? How is it defined? In relation to the text dimensions?). You can also use the rounded rectangle shape from the shapes.misc library (not exactly ellipses but it can be customized very detailed). Or the superellipse? –  Qrrbrbirlbel Apr 5 '13 at 4:46
The ellipse shape is determined by the height and the width. You can only reduce the width of the ellipse by increasing the height and vice versa. You probably need something like a rectangle with rounded corners. –  Marc van Dongen Apr 5 '13 at 6:47
Qrrbrbirlbel's superellipse does have an inner xsep setting, so rather than using negative spaces, you could do: \node[thick, shape=superellipse,superellipse parameter=3, inner xsep=-10mm] at (2,3) {This is a long text that leads to a very fitted node}; –  kmacinnis Apr 6 '13 at 3:25
@kmacinnis this looks like the answer to me. Would you care to write it up? –  Paul Gessler Feb 24 '14 at 13:55

From the comments; setting a negative inner sep value of Jake's superellipse shape is one way to go. But instead you can set the text height and text depth keys deliberately to lower values and get away with it.
Many other things depend on inner sep values so negative values of it is asking for trouble.