The source of the difficulty is that ellipses are constructed in a particular way in TikZ. They are paths that start from the x-axis and proceed counter-clockwise around their centre. The vast majority of the time, the exact parametrisation doesn't matter. You appear to have found the one situation where it does!
In the actual question, you only want to be able to mirror the ellipse, and so draw it starting from the negative x-axis (the title of the question suggests a more flexible approach). That's actually not too hard since we can exploit the symmetry of the ellipse. The key is to provide it with a negative x-radius, since then it will start from the negative x-axis (and proceed clockwise, but we could correct for that by negating the y-radius as well). To do this, we interrupt the call from the node shape to the drawing command and flip the sign of the x-radius. The simplest way to do this is to redefine the \pgfpathellipse
macro to do the negation and then call the original macro. The following code does this.
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{decorations,shapes,decorations.markings}
\makeatletter
\let\origpgfpathellipse=\pgfpathellipse
\def\revpgfpathellipse#1#2#3{%
#2%
\pgf@xa=-\pgf@x
\origpgfpathellipse{#1}{\pgfqpoint{\pgf@xa}{0pt}}{#3}}
\makeatother
\tikzset{
reversed ellipse/.style={
ellipse,
reverse the ellipse%
},
reverse the ellipse/.code={
\let\pgfpathellipse=\revpgfpathellipse
}
}
\begin{document}
\begin{tikzpicture}
\node[ellipse,
draw,
postaction={
decorate,
decoration={
markings,
mark=at position 1 with {
\arrow[line width=5pt,blue]{>}
}
}
}
] at (0,0) {hello world};
\node[reversed ellipse,
draw,
postaction={
decorate,
decoration={
markings,
mark=at position 1 with {
\arrow[line width=5pt,blue]{>}
}
}
}
] at (0,-2) {hello world};
\end{tikzpicture}
\end{document}
Here's the result:
(the arrow got clipped, but you can see where it lies)
Text decorations are somewhat tricky because the text is chopped up into letters and they are rotated according to the underlying path. The decoration library has many options for aligning the text on the path for example it can distribute words along the path depending on whether it sees a whitespace via align={fit to path stretching spaces}
or you can spread all letters etc. The manual is pretty comprehensive on these options. Here you can use a simple circle for the decoration but there are a few issues.
- You have three groups of text to be separated apart.
- Those groups include whitespace chars
- The circle is always drawn starting from the zero angle (rightmost point)
- Because the circle is a closed path the space stretching drives the last group to the first group thinking that the last one should be shifted to the end of the path. Hence first and last group is combined on the right side. We need an invisible element in the end trailing a whitespace char so that the path is divided into three pieces.
So to handle the first issue, we separate three word groups with spaces.
To handle the second issue we replace the whitespaces within the word groups by \space
command (the whitespace after \space
is gobbled so no worries). So TikZ doesn't see the whitespace but the command expands to a whitespace
To handle the third, we rotate the path instead of aligning the decorations.
To handle the fourth issue we put a whitespace and a \space
command as ␣\space
The end result looks like this
\documentclass[12pt]{scrreprt}
\usepackage{courier} %courier font
\usepackage{tikz} % for tikz graphs and colors
\usetikzlibrary{decorations.text} % decorations.text for the text along path feature
\pagestyle{empty} % to suppress page numbers
\begin{document}
\begin{tikzpicture}
\draw[color=black,fill=yellow,fill opacity=1.0] (2.87,-0.98) -- (2.51,-2.05) -- (4.39,-2.66) -- (4.76,-1.6) -- cycle;% yellow rect
\draw[color=black,fill=red,fill opacity=1.0] (3.23,0.19) -- (5.12,-0.43) -- (4.81,-1.5) -- (2.92,-0.88) -- cycle; %red rect
%\draw[double distance=10mm,double=gray,opacity=0.3](0,0) circle (4.4cm); % a double circle
\draw [double distance=10mm,
double=gray,
draw opacity=0.3,
rotate=120,
postaction={
decorate,
decoration={
raise=-1ex,
text along path,
reverse path,
text align={fit to path stretching spaces},
text={|\ttfamily\huge\color{white}|Text\space label\space 1 Unknown Text\space Label\space 2 \space}
}
}
] (0,0) circle (4.4cm);
\end{tikzpicture}
\end{document}
Now you can play around with rotation amount further or insert other elements at the end of the path to change the spacing etc. If you use draw opacity
the text decoration won't be affected from the transparency.
EDIT : To fix the flow direction of Text label 2 within the same path.
\documentclass[12pt]{scrreprt}
\usepackage{courier} %courier font
\usepackage{tikz} % for tikz graphs and colors
\usetikzlibrary{decorations.text} % decorations.text for the text along path feature
\pagestyle{empty} % to suppress page numbers
\begin{document}
\begin{tikzpicture}
\draw[color=black,fill=yellow,fill opacity=1.0] (2.87,-0.98) -- (2.51,-2.05) -- (4.39,-2.66) -- (4.76,-1.6) -- cycle;% yellow rect
\draw[color=black,fill=red,fill opacity=1.0] (3.23,0.19) -- (5.12,-0.43) -- (4.81,-1.5) -- (2.92,-0.88) -- cycle; %red rect
%\draw[double distance=10mm,double=gray,opacity=0.3](0,0) circle (4.4cm); % a double circle
\draw [double distance=10mm,
double=gray,
draw opacity=0.3,
rotate=150,
postaction={
decorate,
decoration={
raise=-1ex,
text along path,
reverse path,
text align={fit to path stretching spaces,right indent=12cm},
text={|\ttfamily\huge\color{white}|Text\space label\space 1 Unknown}
}
},
postaction={
decorate,
decoration={
raise=-1ex,
text along path,
%reverse path,
text align={left indent=3cm,right indent=9cm},%or right indent=15cm,center
text={|\ttfamily\huge\color{white}|Text label 2}
}
}
] (0,0) circle (4.4cm);
\end{tikzpicture}
\end{document}
It can be adjusted further with the right/left indent
keys
Best Answer
This produces something similar to your screen shot.