Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I'd like to create labeled nested ellipses in tikz. The labels should follow the shape of the ellipses. I used a path decoration with pre to move the label to the right place, but I couldn't figure out: a): how to turn it [the mirror option mirrors it in the wrong way] and b): as soon as I include pre and pre length, other options (such as raise or mirror) do not seem to be respected anymore. Has anyone an idea how to solve this?

\documentclass{article}

\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage[american]{babel}
\usepackage{tikz}
\usepackage{xcolor}
\usetikzlibrary{shapes,arrows}
\usetikzlibrary{decorations.pathmorphing, decorations.text}

\begin{document}

\begin{tikzpicture}[decoration=zigzag]
  % ellipses
  \filldraw[fill=gray!10, draw=gray!80] (0,0) ellipse (6.4cm and 3.2cm);
  \filldraw[fill=gray!20, draw=gray!80] (0,0) ellipse (4.8cm and 2.4cm);
  \filldraw[fill=gray!30, draw=gray!80,
            postaction={decorate,
                        decoration={pre=moveto, pre length=3cm, raise=4mm, text along path, text={|\tt|Function 2}}}]
           (0,0) ellipse (3.2cm and 1.6cm);
  \filldraw[fill=gray!40, draw=gray!80] (0,0) ellipse (1.6cm and 0.8cm) node
  {\texttt{Function 1}};
\end{tikzpicture}
\end{document}
share|improve this question
    
Re: the raise not working with pre: just experienced this, and it seems it has been reported as bug, and fixed in 2013: PGF and TikZ -- Graphic systems for TeX / Bugs / #116 Decorations can't be repositioned when pre/post used –  sdaau Apr 17 at 19:41

1 Answer 1

up vote 7 down vote accepted

Instead of decorate the ellipse, you can decorate an arc of this ellipse. And you can choose the direction of this arc.

enter image description here

\documentclass{standalone}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage{tikz}
\usepackage{xcolor}
\usetikzlibrary{shapes,arrows}
\usetikzlibrary{decorations.pathmorphing, decorations.text}
\begin{document}
\begin{tikzpicture}[decoration=zigzag]
  % ellipses
  \filldraw[fill=gray!10, draw=gray!80] (0,0) ellipse (6.4cm and 3.2cm);
  \path[postaction={decorate,
    decoration={
      raise=-1em,
      text along path,
      text={|\tt|Function 4},
      text align=center,
    },
  }] (0,0) ++(110:6.4cm and 3.2cm) arc(110:70:6.4cm and 3.2cm);
  \filldraw[fill=gray!20, draw=gray!80] (0,0) ellipse (4.8cm and 2.4cm);
  \path[postaction={decorate,
    decoration={
      raise=-1em,
      text along path,
      text={|\tt|Function 3},
      text align=center,
    },
  }] (0,0) ++(110:4.8cm and 2.4cm) arc(110:70:4.8cm and 2.4cm);
  \filldraw[fill=gray!30, draw=gray!80] (0,0) ellipse (3.2cm and 1.6cm);
  \path[postaction={decorate,
    decoration={
      raise=-1em,
      text along path,
      text={|\tt|Function 2},
      text align=center,
    },
  }] (0,0) ++(110:3.2cm and 1.6cm) arc(110:70:3.2cm and 1.6cm);
  \filldraw[fill=gray!40, draw=gray!80] (0,0) ellipse (1.6cm and 0.8cm) node
  {\texttt{Function 1}};
\end{tikzpicture}
\end{document}
share|improve this answer
    
If you really want to, you can mirror the text with reverse path, or add space before the text with text align={left indent=<insert favorite length>}, but this answer is a much easier and more elegant way of doing it. –  Count Zero Feb 3 '13 at 0:30
    
Thanks a lot, very good! –  Marius Hofert Feb 3 '13 at 0:44

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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