5

I do not know how to make a pie-chart as the one pictured below, which I drew by hand. I tried using "pgf-pie" for that, but it does not really work as I intend. Could you help me?

enter image description here

\documentclass{article}
\usepackage{pgf-pie}

\newcommand{\QR}[1][n]{\mathcal{QR}_{#1}}
\newcommand{\QNR}[1][n]{\mathcal{QNR}_{#1}}
\newcommand{\QNRP}{\mathcal{QNR}_n^{+1}}
\newcommand{\JNP}{\mathcal{J}_n^{+1}}
\newcommand{\JNM}{\mathcal{J}_n^{-1}}

\begin{document}

\begin{tikzpicture}[scale=1.25]

\pie [rotate = 90, text=inside, color = {yellow!50, green!50}, scale font]
{75/$\QR[n]$,
    25/$\QNR[n]$}

\end{tikzpicture}

\end{document}
1
  • Don't. Please don't Pie charts deliver almost zero information while wasting an inordinate amount of space on the page. There is never ever a case where a pie chart is the preferred style (excepting the collection of pie-chart jokes) . In your example, the meaning of the colors vs. the meaning of the dividing lines is completely unclear, and the labels make it even worse. Jun 6, 2019 at 12:30

3 Answers 3

10

With plain TikZ you could do

\documentclass[tikz,border=3.14mm]{standalone}
\usepackage{amssymb}
\newcommand{\QNR}[1][n]{\mathcal{QNR}_{#1}}
\newcommand{\QNRP}{\mathcal{QNR}_n^{+1}}
\begin{document}
\begin{tikzpicture}[declare function={R=2;}]
 \fill[blue!30] (0,R) arc(90:270:R);
 \fill[yellow] (0,R) arc(90:-90:R);
 \draw (0,0) circle[radius=R] (-R,0) node[left] {$+1$} -| (0,R) node[above] {$\mathbb{Z}/n\mathbb{Z}$};
 \path (135:R/2) node {$\QNR$} (-90:R/2) node  {$\QNRP$} (0:R) node[right]   {$-1$} ;
\end{tikzpicture}
\end{document}

enter image description here

4
  • +1 for declare function! I have not been aware for this possibilitiy.
    – Zarko
    Jun 5, 2019 at 22:27
  • @Zarko Thanks! Note that there is one possible caveat: it is somewhat less straightforward to "undeclare" functions, though possible. That is, if you use several of those in your tikzpictures, try to use them locally in scopes. Never declare them globally outside the tikzpicture.
    – user121799
    Jun 5, 2019 at 22:39
  • thank you for info. For purpose as declare function is used in your answer so far I use \def\R{...}, which also have some limitations.
    – Zarko
    Jun 5, 2019 at 22:54
  • @Zarko Yes, sure. You should never define single-letter macros. For instance, xelatex defines some of those without telling you. The above was just a remark that one may not overdo it with these declare functions, but here it is fine IMHO.
    – user121799
    Jun 5, 2019 at 23:00
4

a small variation of @marmot answer:

\documentclass[tikz, margin=3mm]{standalone}
\usepackage{newtxtext,newtxmath}
\newcommand{\QNR}[1][n]{\mathcal{QNR}_{#1}}
\newcommand{\QNRP}{\mathcal{QNR}_n^{+1}}

\begin{document}

\begin{tikzpicture}[declare function={R=16mm;}]
\node[circle, draw, fill=yellow!30, minimum size=2*R,
      label=left: $+1$,
      label=right:$-1$,
      label=$\mathbb{Z}/n\mathbb{Z}$] (C) {};
\draw[fill=green!30] (C.south) arc (270:90:R);
\draw (C.west) arc (180:90:R) |- cycle;
\node[below=R/2mm]        {$\QNRP$};
\node[above left=R/2mm]   {$\QNR$};
\end{tikzpicture}

\end{document}

enter image description here

3

A pstricks solution:

\documentclass[border=5pt, svgnames]{standalone}
\usepackage{amsfonts}
\usepackage{pst-node, pstricks-add}
\usepackage{auto-pst-pdf}

\newcommand{\QR}[1][n]{\ensuremath{\mathcal{QR}_{#1}}}
\newcommand{\QNR}[1][n]{\ensuremath{\mathcal{QNR}_{#1}}}
\newcommand{\QNRP}{\ensuremath{\mathcal{QNR}_n^{+1}}}
\newcommand{\JNP}{\ensuremath{\mathcal{J}_n^{+1}}}
\newcommand{\JNM}{\ensuremath{\mathcal{J}_n^{-1}}}

\begin{document}

\begin{pspicture}(-2.5,-2)(2.5,2.5)
\psChart[userColor={Yellow!50, LightSteelBlue!80, LightSteelBlue!80,Yellow!50,}]{1,1,1,1}{}{2}
\pscircle(0,0){2}
\psline(2;90)(0,0)(2;180)
\rput[B](1.1;140){\QR} \rput[B](1.1;-90){\QNR}
\uput[r](2;0){$-1$}\uput[l](2;180){$+1$}
\uput[u](2;90){$\mathbb{Z}/ n\mathbb{Z}$}
\end{pspicture}

\end{document} 

enter image description here

You must log in to answer this question.

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