Is there a way to make a pie chart with Tikz so that the labels are not numbers (e.g. 30/70 in my example) but the labels are displayed as variables (e.g. omega and 1- omega)?

Here is what I currently have:

    \pie{30/Stock, 70/Bond}

enter image description here

I do not want it to say 30/70, and want to be able to label it with a Greek letter instead.

  • 1
    Welcome to TeX.SE!. Please try to do something by yourself and then add a minimal working example (MWE) to your post. Without showing any of your effort to draw this diagram, your question is "do-it-for-me" which is unlikely to be answered. – Cragfelt Dec 15 '17 at 21:10
  • I did put in my code. Do you see it? – Zak Fischer Dec 15 '17 at 21:14
  • You can easily modify the code here. – Alan Dec 15 '17 at 21:22
  • Alan could you give a bit more explanation - that diagram has percentages showing up too. How would that be adjusted to get what I'm looking for? – Zak Fischer Dec 15 '17 at 21:25
  • 1
    He might not have seen your comment. You as the owner of the post is notified of all comments, other commenters are not notified unless you write an at-sign followed by the username, e.g. @Alan. That said, try replacing {\p\%}{\t} with {\t}{}. – Torbjørn T. Dec 15 '17 at 21:48

To answer your original question, I don't know if there is any built-in method in pgf-pie to have only textual labels and not the numbers, but it is possible to patch the macro responsible for making a slice to achieve that:

output of first code with pgf-pie

\patchcmd{\pgfpie@slice}% this is the macro we're patching
{\scalefont{#3}\shortstack{#4\\\beforenumber#3\afternumber}}% find this
{\scalefont{#3}#4}% and replace with this
    \pie[text=inside]{30/$\omega$, 70/$1-\omega$}

If you want to use the code from the example Alan mentioned, you'll need to modify it to use a third loop variable, for defining the colour. I indicated in the code where I made modifications.

output of code

% Original code from http://www.texample.net/tikz/examples/pie-chart/
% by Robert Vollmert
\newcommand{\slice}[5]{% changed 4 to 5, fifth argument to define colour

  % slice
  % add #5 after fill=
  \draw[thick,fill=#5] (0,0) -- (#1:1) arc (#1:#2:1) -- cycle;

  % outer label
  \node[label=\midangle:#4] at (\midangle:1) {};

  % inner label
  \pgfmathparse{max(\temp,-0.5) + 0.8}
  \node at (\midangle:\innerpos) {#3};


% add third loop variable for colour
\foreach \p/\t/\clr in {30/$\omega$/blue!20, 70/$1-\omega$/red!30}
          {\t}{}{\clr} % added fifth argument, {\clr}


Finally, for a simple two-part pie here is one way of doing it from scratch.

output of code

\filldraw[draw=black,fill=blue!30] (0,0) -- (0:2cm) arc[start angle=0,end angle=120,radius=2cm] -- cycle;
\filldraw[draw=black,fill=red!30] (0,0) -- (120:2cm) arc[start angle=120,end angle=360,radius=2cm] -- cycle;
\node at (60:1cm) {$\omega$};
\node at (240:1cm) {$1-\omega$};
  • Perfect! This got the job done, and then I added in two nodes for the stock/bond labes: \node at (240:2.5cm) {Bond}; \node at (60:2.5cm) {Stock}; – Zak Fischer Dec 18 '17 at 1:30
  • @ZakFischer If the answer worked for you, please consider accepting it by clicking on the check mark left of it. – marmot Jan 9 at 0:03
  • @marmot Got it - done! – Zak Fischer Jan 9 at 0:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.