3

EDIT The accepted answer completely solves my immediate problem, but for more detailed analysis of the underlying issue please refer to answer by cfr. Basically, pstricks and pdfTex don't mix well.

I have a beamer presentation with a lot of pie charts. I use pgf-pie package because it is easy and (mostly) does what I need. I have one particular pie-chart that should have no labels at all. I have tried adding

/tikz/nodes={text opacity=0,overlay}

to the code following advice found here.

Small pie-chart without any numbers or text

\documentclass{standalone}
\usepackage{pgf-pie}
\begin{document}

\begin{tikzpicture}
\pie [explode=0.1, color={blue!70, green!80, red, yellow} ,/tikz /nodes={text opacity=0,overlay}]{10/, 20/, 30/, 40/}
\end{tikzpicture}
\end{document}

Now, the strange thing is, the code works well in the example above (standalone class). However, it doesn't seem to do anything inside a beamer presentation, i.e. the labels still show. It seems that there is some sort of package conflict. How could I enable this to work in the beamer presentation? I know there are other ways to produce this but pgf-pie is quite handy otherwise.

\documentclass[12pt,compress]{beamer}
\usetheme{Warsaw}

\setbeamertemplate{navigation symbols}{}%remove navigation symbols
\setbeamercolor{alerted text}{fg=magenta}

%\usepackage[latin1]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{wasysym}
\usepackage{multicol}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{graphicx}
\usepackage{xcolor}
%\usepackage{iwona}
\usepackage{wrapfig}
\input{FactorTree}
\usepackage{pstricks}
\usetikzlibrary{matrix}
\usepackage{tkz-euclide}
\usetkzobj[all]
\usepackage{xlop}
\usepackage{tcolorbox}
\usepackage{pgfplots}
\usepackage{pgf-pie}
\usepackage[makeroom]{cancel}
\input{longdiv}

Pie Chart Without Labels

Niko Z.
  • 431
  • Where can pgf-pie.sty be found? It is not in TeX Live. – cfr Sep 11 '16 at 16:21
  • Did you read the second answer to the question you linked to? – cfr Sep 11 '16 at 16:22
  • I have downloaded package pgf-pie from CTAN and installed manually in my local texmf tree. Here is a link to the package. link I have read the second answer to to the question linked. I am aware there are other ways of getting the desired pie-chart, for example using straight up Tikz as explained in the linked answer or using tikz-euclid package (a bit simpler syntax). However, pgf-pie has the simplest syntax and I need to produce many pie charts quickly for my presentations, so it really fits my needs best. – Niko Z. Sep 11 '16 at 17:29
  • It would be easier if you provided complete minimal code for the non-working case. Also, the working code doesn't compile. – cfr Sep 11 '16 at 18:37
  • Where is FactorTree.tex to be found? If I ignore that error, I get further complaints if I use your preamble to try to construct a minimal example showing the problem. The problem is not Beamer alone, though. – cfr Sep 11 '16 at 18:45
  • The underlying problem here is that you are attempting to use pstricks with pdfTeX and that is never going to work properly like this. – cfr Sep 11 '16 at 19:28
  • @cfr FactorTree.tex is a local file that insert definitions needed to display prime factorization trees. The problem with pie charts persists even if I comment out that line. The issue is indeed in using 'pstricks'. If I don't load that package the pie chart can be compiled with pdflatex as well as xelatex. – Niko Z. Sep 12 '16 at 14:01
  • Just remember when posting code that people here need to be able to use it to reproduce problems. We can do that if it uses a file only you have. Where it isn't part of the problem, remove it along with other unnecessary stuff before posting. When it is part of the problem, of course, we need access to the file (or the relevant part of it) in order to be able to help. – cfr Sep 12 '16 at 15:17
  • I'll keep that in mind. I thought I had removed all extraneous parts, but I was wrong due to complexity of the document. You have pinpointed the problem with pstricks though. In this specific case, the preamble of the 'presentation' is made of many 'input' and 'include' files. The slides include every single lesson I teach in the course of the year and so the preamble gets a bit complex with a lot of extra (re)definitions needed to enable needed functionality. No excuse for being sloppy though. – Niko Z. Sep 12 '16 at 18:52

4 Answers4

4

You can just remove the text in /tikz/nodes={text opacity=0,overlay}% <-. I hope this helps:

\documentclass[12pt,compress]{beamer}
\usepackage{pgf-pie}
\usetheme{Warsaw}

\setbeamertemplate{navigation symbols}{}%remove navigation symbols
\setbeamercolor{alerted text}{fg=magenta}

%\usepackage[latin1]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{wasysym}
\usepackage{multicol}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{graphicx}
\usepackage{xcolor}
%\usepackage{iwona}
\usepackage{wrapfig}
%\input{FactorTree}
\usepackage{pstricks}
\usetikzlibrary{matrix}
\usepackage{tkz-euclide}
\usetkzobj[all]
\usepackage{xlop}
\usepackage{tcolorbox}
\usepackage{pgfplots}
\usepackage[makeroom]{cancel}
%\input{longdiv}
\begin{document}

\begin{frame}
\begin{tikzpicture}
\pie [color={blue!70, green!80, red, yellow}, /tikz/nodes={opacity=0,overlay}% <-
]{10, 20, 30, 40}
\end{tikzpicture}

\end{frame}

\end{document}

enter image description here

  • It works, thanks! However, it only works when I compile with xelatex but it doesn't work when I compile with pdflatex. Does anyone know why that would be the case? If possible I would prefer to work with pdflatex. – Niko Z. Sep 11 '16 at 14:25
  • @cfr The answer does (almost) solve my problem. Majid has removed the word text from the original code, and now it does compile in beamer, but only when xelatex is used. I prefer pdflatex because xelatex does not always compile other pieces of code in my presentation. – Niko Z. Sep 11 '16 at 17:27
  • Sorry. Should have read more carefully. – cfr Sep 11 '16 at 18:23
3

The command \pgfpie@slice defined in pgf-pie.sty to draw circular diagram

\newcommand{\pgfpie@slice}[8]{
  \pgfmathparse{0.5*(#1)+0.5*(#2)}
  \let\midangle\pgfmathresult

  \path (#8) -- ++(\midangle:#5) coordinate(O);

  \pgfmathparse{#7+#5}
  \let\radius\pgfmathresult

  % slice
  \draw[line join=round, fill=#6, \style] (O) -- ++(#1:#7) arc (#1:#2:#7) -- cycle;

  \pgfmathparse{min(((#2)-(#1)-10)/110*(-0.3),0)}
  \let\temp\pgfmathresult
  \pgfmathparse{(max(\temp,-0.5) + 0.8)*#7}
  \let\innerpos\pgfmathresult

  \ifthenelse{\equal{\pgfpie@text}{inside}}
  {
    % label and number together
    \path (O) -- ++(\midangle:\innerpos) node
    {\scalefont{#3}\shortstack{#4\\\beforenumber#3\afternumber}};
  }
  {
    % label
    \iflegend
    \else
    \path (O) -- ++ (\midangle:\radius)
    node[inner sep=0, \pgfpie@text=\midangle:#4]{};
    \fi

    % number
    \path (O) -- ++(\midangle:\innerpos) node
    {\scalefont{#3}\beforenumber#3\afternumber};
  }
}

Numbers inside circle are defined with argument #3 of the command \pgfpie@slice, you can for example modify the definition of \beforenumber and \afternumber to obtain a phantom like command to hide numbers

For this you can just add before number=\phantom and after number=

Code

\documentclass{beamer}
\usepackage{pgf-pie}
\usepackage{pstricks}

\begin{document}

\begin{frame}
\begin{tikzpicture}
\pie [explode=0.1,color={blue!70, green!80, red, yellow},before number=\phantom,after number=]
{10/, 20/, 30/, 40/}
\end{tikzpicture}
\end{frame}

\end{document}

enter image description here

Salim Bou
  • 17,021
  • 2
  • 31
  • 76
2

First, here's a minimal example which demonstrates the issue.

\documentclass[border=10pt,multi,tikz]{standalone}
\usepackage{pstricks}
\usepackage{pgf-pie}
\begin{document}
\begin{tikzpicture}
  \pie [explode=0.1, color={blue!70, green!80, red, yellow}, /tikz/nodes={text opacity=0, overlay}]{10/, 20/, 30/, 40/}
\end{tikzpicture}
\end{document}

MNWE output

The issue here is that pstricks requires processing which can incorporate postscript into the output, but pdfTeX does not include a postscript interpreter and cannot make sense of these commands. The console output demonstrates the issue fairly clearly.

Non-PDF special ignored!
Non-PDF special ignored!
Non-PDF special ignored!
Non-PDF special ignored!
Non-PDF special ignored!
Non-PDF special ignored!
Non-PDF special ignored!

Colours and transparency, among other things, are handled in the driver rather than in the TeX code. PGF/TikZ attempts to hide the differences between different drivers by providing an interface which abstracts away from these differences. This means that when you compile with pdfTeX, say, PGF/TikZ interprets your commands in one way and when you compile with another engine, it may interpret them in another.

pstricks arranges things so that its commands will work by outputting postscript \specials. But you are compiling with pdfTeX, so graphicx and xcolor and PGF/TikZ arrange things so that their commands will work by outputting PDF \specials.

Even though your example does not include any pstricks-dependent content in the document body, loading the package makes changes which obviously result in the PGF/TikZ code produced by the commands in your tikzpicture. In particular, non-PDF \specials are being output. Because pdfTeX cannot handle these, they are simply ignored. This breaks, for example, transparency in tikzpictures completely.

Here's an even more minimal example demonstrating the issue.

\documentclass[border=10pt,multi,tikz]{standalone}
\begin{document}
\begin{tikzpicture}
  \node [fill=red, text=yellow, text opacity=0] {X};
\end{tikzpicture}
\end{document}

produces

expected

as expected, while

\documentclass[border=10pt,multi,tikz]{standalone}
\usepackage{pstricks}
\begin{document}
\begin{tikzpicture}
  \node [fill=red, text=yellow, text opacity=0] {X};
\end{tikzpicture}
\end{document}

produces

not-exactly-expected

None of this is really surprising. As written, the code can't be expected to work because whatever you need pstricks for, it is going to fail. So, the first thing to ask is whether you need pstricks at all. I would guess you aren't using it because otherwise you'd see other problems in the output and not just issues with transparency in tikzpictures: your pspictures wouldn't work either.

If you do need pstricks, then the easiest options involve using an engine which can support it properly. This need not be XeTeX. Regular TeX is certainly an option, for example, with conversion on from DVI by one of the standard routes.

Otherwise, you need to think about how you are supporting the code you need postscript for in order to avoid bigger problems than lack of transparency in PGF/TikZ.

For the very particular problem in the question, you can certainly work around the issue. But no such solution can be recommended as it will patch over the superficial symptoms of the problem, rather than addressing the underlying cause. It is that underlying cause which you need to tackle in order for things to generally work as expected, as opposed to appearing to work in some particular case or other.

cfr
  • 198,882
  • I can confirm that removing pstricks resolves the problem. I do need it for some other slides in the same presentation though. This will require a bit of further reading on my part. Thanks for the detailed explanation. – Niko Z. Sep 12 '16 at 14:20
0

I cant reproduce your problem with recent version of MikTeX the following MWE works in pdfLaTeX without errors (only two warning regarding substitutions of font sizes). Maybe you have outdated LaTeX installation?

For test I made really MWE (from yours I delete all packages which are not relevant to draw a pie):

\documentclass[12pt,compress]{beamer}
\usetheme{Warsaw}
\setbeamertemplate{navigation symbols}{}%remove navigation symbols
\setbeamercolor{alerted text}{fg=magenta}

\usepackage[utf8]{inputenc}% <-- added
\usepackage[T1]{fontenc}

\usepackage{pgf-pie}

\begin{document}
\begin{frame}
    \begin{tikzpicture}
\pie[color={blue!70, green!80, red, yellow}, 
     /tikz/nodes={text opacity=0}% <-
]{10, 20, 30, 40}
    \end{tikzpicture}
\end{frame}
\end{document}

enter image description here

Zarko
  • 296,517