2

I am able to easily draw single circular sectors using a newcommand such as

\documentclass[12pt]{standalone}

\usepackage{tikz}
\usetikzlibrary {shapes.geometric}

\newcommand*{\eAngle}[2]{%
   \begin{tikzpicture}[anchor=base, baseline=-0.65ex]
       \node[circular sector, fill=#1, rotate=#2, minimum size=0.1cm] at (0,0) {};
   \end{tikzpicture}%
}

\begin{document}
  \eAngle{red}{45} 
\end{document}

This lets me set the color and rotation of the sector. These get inserted into paragraphs eg

This is an angle: \eAngle{red}{45}

I should add, I don't care how its done, I happen to use circular sector shape as I thought that would be the thing to use. But any other solution would be acceptable.

Using the circular sector shape I can't figure out how to change the arc width of the sector. I thought I could use the key, circular sector angle but that also appears change the size of the sector by making it longer as the angles gets smaller. The desired effect is shown in the figure below, same radius but different angle:

enter image description here

any suggestions on how to do this?

Here is another example using the command above. The rotation orientation is unchanged at zero (second argument) but the angle at the tip (third argument) is progressively increased:

  Here is a pie \eAngle{red}{0}{10}, \eAngle{red}{0}{20}, \eAngle{red}{0}{40}, \eAngle{red}{0}{60}, \eAngle{red}{0}{80}

This yields the following image. Note, as the angle gets bigger at the tip the sector radius gets shorter (left to right). I'd like to have a fixed radius as the angle is changed.

The following is not what I want, I want a fixed radius (what looks like the length in the images below)

enter image description here

2
  • Do you need this to actually be a node? You can just draw a circular sector as a normal path. The inner seps might interfere with the size of the node. Oct 29, 2023 at 22:07
  • I don't mind how it's drawn so long as I can rotate it easily around the center (center of the image not eg the point of the sector) to get different orientations but also different angles at the point (but same radius)
    – rhody
    Oct 29, 2023 at 23:45

2 Answers 2

2

Code

\documentclass{article}
\usepackage{tikz}
\tikzset{
  @circular sector/radius/.initial=1,
  @circular sector/tip/.initial=0,    % where the tip points to (i.e. the rotation)
  @circular sector/angle/.initial=90, % the opening of the sector
  @circular sector/.search also=/tikz,
  @circular sector/.code=\pgfqkeys{/tikz/@circular sector}{#1},
  circular sector/.style={
    @circular sector={#1},
    rotate=\pgfkeysvalueof{/tikz/@circular sector/tip},
    insert path={
      \pgfextra{% values we need more than once
        \pgfmathsetmacro\halfAng{(\pgfkeysvalueof{/tikz/@circular sector/angle})/2}%
        \pgfmathsetmacro\radius{\pgfkeysvalueof{/tikz/@circular sector/radius}}}
      (0:{2*\radius*sin(\halfAng)/(3*rad(\halfAng))}) -- +(180-\halfAng:\radius)
      arc[start angle=180-\halfAng, end angle=180+\halfAng, radius=\radius]
      -- cycle}}}
\newcommand*\eAngle[1][]{% \fontdimen22\textfont2 is “vertical center”
                         % this puts the center of the sector in the “middle”
  \tikz[baseline=+-\fontdimen22\textfont2]\fill[circular sector={#1}];}
\begin{document}
Points to $ 30^\circ$ with angle of $10^\circ$: \eAngle[red, tip=30, angle=10]

Points to $250^\circ$ with angle of $45^\circ$:
                                   \eAngle[blue, tip=250, angle=45, radius=.7]

\foreach[evaluate={\c=\ang/3.6;}] \ang in {0, 10, ..., 359}{
  \eAngle[red!\c!blue, angle=30, tip=\ang]}
\end{document}

Output

enter image description here

1
  • I confirm this works. I'm am surprised it was this involved. Much obliged for your solution.
    – rhody
    Oct 30, 2023 at 0:53
2

Like this:

enter image description here

with this code (adapted from your's one):

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary {shapes.geometric}

\newcommand*{\eAngle}[4]{%
    \begin{tikzpicture}[anchor=base, baseline=-0.65ex]
        \node[circular sector,circular sector angle=#3, fill=#1, text=white, rotate=#2, minimum size=.1cm] at (0,0) {#4};
    \end{tikzpicture}%
}

\begin{document}
    \eAngle{red}{0}{30}{Testo}  \eAngle{brown}{135}{90}{20\%} \eAngle{cyan}{90}{20}{Testo di prova}
\end{document}

ADDENDUM: Changes in code:

\begin{document}
    \eAngle{red}{0}{20}{\hspace*{1cm}}  \eAngle{brown}{135}{90}{\;\;\;} \eAngle{cyan}{0}{120}{\hspace*{1.5cm}}
\end{document}

Output:

enter image description here

12
  • But the radius of the sector changes as the angle at the tip changes. I need the sector radius to stay fixed This is true even if I don't include the text you added.
    – rhody
    Oct 29, 2023 at 23:53
  • @rhody I have changed the radius of sector depending of the text inside; plus i changed also di angle. The radius change, starting from a minimum, only with the length of the text inside. Oct 30, 2023 at 0:03
  • In your example I need to remove the text because there won't be any text in the sectors when I draw them. Plus the text in this case is changing the radius of the sectors. However it I run the code without the text, the blue sector has a larger radius (tip to curved end) than the red sector and the brown sector has a smaller radius (tip to curved end) then the red sector. I need the sectors to have the same tip to curve length even though the tip angles are different.
    – rhody
    Oct 30, 2023 at 0:09
  • I bad approach I came up with is to store the images as small pdf files and use \rotatebox and \includegraphics to draw the shapes. But this is far from idea, as I'd have to store multiple pdfs for each color and each tip angle I need to use.
    – rhody
    Oct 30, 2023 at 0:11
  • @rhody I dont understand what exactly You want. If You dont want to up vote and/or accept my answer no problem... Oct 30, 2023 at 0:21

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .