3

I have to rotate this figure ninety degree counter-clockwise and I have to fill it with some colour.

\documentclass[border=1mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{decorations.markings,arrows}
\begin{document}
\begin{tikzpicture}
[thick
,decoration =
{markings
,mark=at position 0.5 with {\arrow{stealth'}}
}
]
 \newdimen\R     
 \R=2.7cm
  \node {$x^2y^2z^2$};
\draw[-stealth'] (-160:{0.4*\R}) arc (-150:150:{0.4*\R});
 \foreach \x/\l in
{120/$x^2z^2$,
 240/$x^2y^2$,
 360/$y^2z^2$
}
\draw[postaction={decorate}] ({\x-120}:\R) -- node[auto,swap]{\l} (\x:\R);
\foreach \x/\l/\p in
{ 
 120/{$x^2z$}/above,
 240/{$xy^2$}/below,
 360/{$yz^2$}/right
}
\node[inner sep=2pt,circle,draw,fill,label={\p:\l}] at (\x:\R) {};
\end{tikzpicture}
\end{document}

TikZ figure

Troy
  • 13,741
  • You just may add rotate=90 to the options of \begin{tikzpicture} to rotate your picture. Probably you have to manually adapt some of the nodes. But what exactly do you want to fill with colour? – Jürgen Mar 10 '17 at 14:30

3 Answers3

3

You didn't specify which color, so I chose pink. Note that TikZ internal rotation does not affect the above, below, left, right specifications. \rotatebox rotates everything.

\documentclass[border=1mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{decorations.markings,arrows,backgrounds}

\newdimen\SomeUniqueName% permanently uses up one register

\begin{document}
\rotatebox{90}{\begin{tikzpicture}
[thick
,decoration = {markings,mark=at position 0.5 with {\arrow{stealth'}}}
%,rotate=90% lines only
%,every node/.style={rotate=90}% text only
]
 \let\R=\SomeUniqueName% local to environment
 \R=2.7cm
  \node {$x^2y^2z^2$};
\draw[-stealth'] (-160:{0.4*\R}) arc (-150:150:{0.4*\R});
 \foreach \x/\l in
{120/$x^2z^2$,
 240/$x^2y^2$,
 360/$y^2z^2$
}
\draw[postaction={decorate}] ({\x-120}:\R) -- node[auto,swap]{\l} (\x:\R);
\foreach \x/\l/\p in
{ 
 120/{$x^2z$}/above,
 240/{$xy^2$}/below,
 360/{$yz^2$}/right
}
\node[inner sep=2pt,circle,draw,fill,label={\p:\l}] at (\x:\R) {};
\begin{scope}[on background layer]
  \fill[pink] (current bounding box.south west) rectangle (current bounding box.north east);
\end{scope}
\end{tikzpicture}}
\end{document}

demo

John Kormylo
  • 79,712
  • 3
  • 50
  • 120
3

To fill the interior with some colour, you need a closed path, using e.g.

\draw[fill=pink] (0:\R)
  \foreach \x/\l in
    {120/$x^2z^2$,
     240/$x^2y^2$,
     360/$y^2z^2$
    }
  {-- node[auto,swap]{\l} (\x:\R)};

To decorate each segment of this path, we can use a technique described here.

\tikzset{
  % style to apply some styles to each segment of a path
  on each segment/.style={
    decorate,
    decoration={
      show path construction,
      moveto code={},
      lineto code={
        \path [#1]
        (\tikzinputsegmentfirst) -- (\tikzinputsegmentlast);
      },
      curveto code={
        \path [#1] (\tikzinputsegmentfirst)
        .. controls
        (\tikzinputsegmentsupporta) and (\tikzinputsegmentsupportb)
        ..
        (\tikzinputsegmentlast);
      },
      closepath code={
        \path [#1]
        (\tikzinputsegmentfirst) -- (\tikzinputsegmentlast);
      },
    },
  },
  % style to add an arrow in the middle of a path
  mid arrow/.style={postaction={decorate,decoration={
        markings,
        mark=at position .5 with {\arrow[#1]{stealth'}}
      }}},
}
...
\draw[postaction={on each segment={mid arrow}},fill=pink] (0:\R)
... (continue like above)

When filling the interior, everything is covered that has been drawn there before, so we have to move the code for the arc and the central label downwards.

Regarding rotation, you have to decide whether the labels should stay horizontal (option rotate=90) or whether the baseline should be rotated as well, to be read with tilted head (\rotatebox of the whole tikzpicture).

enter image description here

\documentclass[border=1mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{decorations.pathreplacing,decorations.markings,arrows}
% From https://tex.stackexchange.com/a/69225
\tikzset{
  % style to apply some styles to each segment of a path
  on each segment/.style={
    decorate,
    decoration={
      show path construction,
      moveto code={},
      lineto code={
        \path [#1]
        (\tikzinputsegmentfirst) -- (\tikzinputsegmentlast);
      },
      curveto code={
        \path [#1] (\tikzinputsegmentfirst)
        .. controls
        (\tikzinputsegmentsupporta) and (\tikzinputsegmentsupportb)
        ..
        (\tikzinputsegmentlast);
      },
      closepath code={
        \path [#1]
        (\tikzinputsegmentfirst) -- (\tikzinputsegmentlast);
      },
    },
  },
  % style to add an arrow in the middle of a path
  mid arrow/.style={postaction={decorate,decoration={
        markings,
        mark=at position .5 with {\arrow[#1]{stealth'}}
      }}},
}
\begin{document}
\begin{tikzpicture}[thick,rotate=90]
 \newdimen\R     
 \R=2.7cm
\draw[postaction={on each segment={mid arrow}},fill=pink] (0:\R)
  \foreach \x/\l in
 {120/$x^2z^2$,
  240/$x^2y^2$,
  360/$y^2z^2$
 }
 {-- node[auto,swap]{\l} (\x:\R)};
  \node {$x^2y^2z^2$};
\draw[-stealth'] (-150:{0.4*\R}) arc (-150:150:{0.4*\R});
\foreach \x/\l/\p in
{ 
 120/{$x^2z$}/above,
 240/{$xy^2$}/below,
 360/{$yz^2$}/right
}
\node[inner sep=2pt,circle,draw,fill,label={\p:\l}] at (\x:\R) {};
\end{tikzpicture}
\end{document}
gernot
  • 49,614
3

Triggered by @Zarko's comment on my other solution, here is a simpler solution that is preferable if you don't want to generalize the triangle to much more complicated structures. Note the use of named coordinates. If you want to rotate the picture, you just have to modify three coordinates (and maybe the positions of some labels).

\documentclass[border=1mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{decorations.markings,arrows}
\begin{document}
\begin{tikzpicture}%
  [decoration    = {markings,mark=at position 0.5 with {\arrow{stealth'}}},
   vertex/.style = {inner sep=2pt,circle,draw,fill,label={#1}},
   edge/.style   = {postaction={decorate},thick}
  ]
  \newcommand\R{2.7}
  \coordinate (A) at (210:\R);
  \coordinate (B) at (330:\R);
  \coordinate (C) at (90:\R);
  \path[fill=pink] (A)--(B)--(C)--cycle;
  \draw[edge] (A) node[vertex={below:$x^2z$}]{} -- node[below]{$x^2y^2$} (B);
  \draw[edge] (B) node[vertex={below:$xy^2$}]{} -- node[right]{$y^2z^2$} (C);
  \draw[edge] (C) node[vertex={above:$yz^2$}]{} -- node[left ]{$x^2y^2$} (A);
  \node {$x^2y^2z^2$};
  \draw[-stealth',thick] (-150:{0.4*\R}) arc (-150:150:{0.4*\R});
\end{tikzpicture}
\end{document}

enter image description here

gernot
  • 49,614
  • challenge is (as response to your comment after first answer), to add parameter by which you rotate the image for any desired angle and node and all labels haw correct placement :). nice answer! – Zarko Mar 10 '17 at 16:48