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)
Here is a solution based on Using a pgfplots-style legend in a plain-old tikzpicture. There are two examples: in the first one, the descriptions in the legend are centered, while in the second one, the descriptions are left aligned.
To define numbers in the legend, I added a key number in legend
:
% definition to insert numbers
\pgfkeys{/pgfplots/number in legend/.style={%
/pgfplots/legend image code/.code={%
\node at (0.295,0){#1};
},%
},
}
Centered descriptions
The example:
\documentclass[a4paper,11pt]{article}
\usepackage{tikz}
\usetikzlibrary{calc,shadings}
\usepackage{pgfplots}
% Code from Christian Feuersänger
% https://tex.stackexchange.com/questions/54794/using-a-pgfplots-style-legend-in-a-plain-old-tikzpicture#54834
% argument #1: any options
\newenvironment{customlegend}[1][]{%
\begingroup
% inits/clears the lists (which might be populated from previous
% axes):
\csname pgfplots@init@cleared@structures\endcsname
\pgfplotsset{#1}%
}{%
% draws the legend:
\csname pgfplots@createlegend\endcsname
\endgroup
}%
% makes \addlegendimage available (typically only available within an
% axis environment):
\def\addlegendimage{\csname pgfplots@addlegendimage\endcsname}
%%--------------------------------
% definition to insert numbers
\pgfkeys{/pgfplots/number in legend/.style={%
/pgfplots/legend image code/.code={%
\node at (0.295,-0.0225){#1};
},%
},
}
\begin{document}
\begin{tikzpicture}
\draw (0,0)--(10,0);
\draw(0,-0.2)--(0,0.2)node[above,red]{\small{0}};
\draw(10,-0.2)--(10,0.2)node[above,blue]{\small{1}};
%------------------%
\foreach \m[count=\mi] in {0.909090909,...,9.090909090}
\draw(\m,-0.1)--(\m,0.1) node[anchor=north](a\mi){};
\draw[dotted]($(a2)+(0,0.1)$)--($(a2)+(0,0.4)$);
\draw[dotted]($(a3)+(0,0.1)$)--($(a3)+(0,0.4)$);
\draw[stealth-stealth,red,opacity=0.4]($(a3)+(0,0.4)$)--($(a2)+(0,0.4)$)node[anchor=south west,xshift=0.23cm,black,opacity=1]{\small{$R$}};
%------------------%
\foreach \x/\xtext in {0.7/$u_1$,1.2/$u_2$,4.5/$u_3$,5.2/$u_4$,5.6/$u_5$,7.5/$u_6$}
\shade[ball color=blue] (\x,0 ) circle (0.1cm) node[below=0.1cm]{\small{\xtext}};
%------------------%
% inf user
\shade[ball color=green] (0,0 ) circle (0.1cm) node[below=0.1cm]{\small{$u_{inf}$}};
\begin{customlegend}[
legend entries={ % <= in the following there are the entries
$R$: infection radius,
$u_i$: users,
$u_{inf}$: initial infected user,
social space max dimension,
social space min dimension,
example of rectangle
},
legend style={at={(4.5,3.5)},font=\footnotesize}] % <= to define position and font legend
% the following are the "images" and numbers in the legend
\addlegendimage{stealth-stealth,red,opacity=0.4}
\addlegendimage{mark=ball,draw=white}
\addlegendimage{mark=ball,ball color=green,draw=white}
\addlegendimage{number in legend=1,blue}
\addlegendimage{number in legend=0,red}
\addlegendimage{area legend,orange,fill=orange!20}
\end{customlegend}
\end{tikzpicture}
\end{document}
which gives:
Left aligned descriptions
The code is:
\documentclass[a4paper,11pt]{article}
\usepackage{tikz}
\usetikzlibrary{calc,shadings}
\usepackage{pgfplots}
% Code from Christian Feuersänger
% https://tex.stackexchange.com/questions/54794/using-a-pgfplots-style-legend-in-a-plain-old-tikzpicture#54834
% argument #1: any options
\newenvironment{customlegend}[1][]{%
\begingroup
% inits/clears the lists (which might be populated from previous
% axes):
\csname pgfplots@init@cleared@structures\endcsname
\pgfplotsset{#1}%
}{%
% draws the legend:
\csname pgfplots@createlegend\endcsname
\endgroup
}%
% makes \addlegendimage available (typically only available within an
% axis environment):
\def\addlegendimage{\csname pgfplots@addlegendimage\endcsname}
%%--------------------------------
% definition to insert numbers
\pgfkeys{/pgfplots/number in legend/.style={%
/pgfplots/legend image code/.code={%
\node at (0.125,-0.0225){#1}; % <= changed x value
},%
},
}
\pgfplotsset{
every legend to name picture/.style={west}
}
\begin{document}
\begin{tikzpicture}
\draw (0,0)--(10,0);
\draw(0,-0.2)--(0,0.2)node[above,red]{\small{0}};
\draw(10,-0.2)--(10,0.2)node[above,blue]{\small{1}};
%------------------%
\foreach \m[count=\mi] in {0.909090909,...,9.090909090}
\draw(\m,-0.1)--(\m,0.1) node[anchor=north](a\mi){};
\draw[dotted]($(a2)+(0,0.1)$)--($(a2)+(0,0.4)$);
\draw[dotted]($(a3)+(0,0.1)$)--($(a3)+(0,0.4)$);
\draw[stealth-stealth,red,opacity=0.4]($(a3)+(0,0.4)$)--($(a2)+(0,0.4)$)node[anchor=south west,xshift=0.23cm,black,opacity=1]{\small{$R$}};
%------------------%
\foreach \x/\xtext in {0.7/$u_1$,1.2/$u_2$,4.5/$u_3$,5.2/$u_4$,5.6/$u_5$,7.5/$u_6$}
\shade[ball color=blue] (\x,0 ) circle (0.1cm) node[below=0.1cm]{\small{\xtext}};
%------------------%
% inf user
\shade[ball color=green] (0,0 ) circle (0.1cm) node[below=0.1cm]{\small{$u_{inf}$}};
\begin{customlegend}[legend cell align=left, %<= to align cells
legend entries={ % <= in the following there are the entries
$R$: infection radius,
$u_i$: users,
$u_{inf}$: initial infected user,
social space max dimension,
social space min dimension,
example of rectangle
},
legend style={at={(4.5,3.5)},font=\footnotesize}] % <= to define position and font legend
% the following are the "images" and numbers in the legend
\addlegendimage{stealth-stealth,red,opacity=0.4}
\addlegendimage{mark=ball,draw=white}
\addlegendimage{mark=ball,ball color=green,draw=white}
\addlegendimage{number in legend=1,blue}
\addlegendimage{number in legend=0,red}
\addlegendimage{area legend,orange,fill=orange!20}
\end{customlegend}
\end{tikzpicture}
\end{document}
Result:
Best Answer
You can set the code that's used to draw the legend image using
legend image code/.code={ ...}
: