When I Include this diagram to my memoir document

% Requires \usetikzlibrary{shadows,positioning,backgrounds}

  % some colors
  % some styles
      minimum height=5mm,
      inner sep=.7mm,
      outer sep=0mm,
      text width=10mm,
      text centered,
      line width=.25mm,
      top color=#1!5,
      bottom color=#1!40,
      shading angle=0,
      rounded corners=2.3mm,
      drop shadow={fill=#1!40!gray,fill opacity=.8},
    link/.style={-latex,links,line width=.3mm},
  % Pascal's triangle
  % row #0 => value is 1
  \node[box=odd] (p-0-0) at (0,0) {1};
  \foreach \row in {1,...,14} {
     % col #0 => value is 1
    \node[box=odd] (p-\row-0) at (-\row/2,-\row) {1};
    \foreach \col in {1,...,\row} {
      % iterative formula : val = precval * (row-col+1)/col
      % (+ 0.5 to bypass rounding errors)
      % position of each value
      \coordinate (pos) at (-\row/2+\col,-\row);
      % odd color for odd value and even color for even value
      \ifnum \rest=0
        \node[box=even] (p-\row-\col) at (pos) {\value};
        \node[box=odd] (p-\row-\col) at (pos) {\value};
      % for arrows and plus sign
      \ifnum \col<\row
        \node[plus,above=0mm of p-\row-\col]{+};
        \draw[link] (p-\prow-\pcol) -- (p-\row-\col);
        \draw[link] ( p-\prow-\col) -- (p-\row-\col);
    % filling and drawing with the same color to enlarge background
    \path[draw=back,fill=back,line width=5mm,rounded corners=2.5mm]
    (  p-0-0.north west) -- (  p-0-0.north east) --
    (p-14-14.north east) -- (p-14-14.south east) --
    ( p-14-0.south west) -- ( p-14-0.north west) --

This package doesn't work


and when I remove the package the diagram looks fine. How could I resolve this and get both of them(the reference and the diagram at once)?

  • 2
    Please, provide Minimal Working Example (MWE) which we can copy to our computers and test it to see, where is your problem. So far from your code snippets doesn't follow, that they contain some error. – Zarko Jun 20 '16 at 12:03
  • 1
    Also, what does 'doesn't work' mean? Do you get a compilation error? What is it? Does it give undesirable output? What's wrong with it? When you add your MWE, the answers may be obvious, but it is always better not to assume that. In the case of an error, it matters we know which error you get so we can tell if it is reproducing. In the case of undesired output, it matters a lot that we know what you find undesirable. – cfr Jun 20 '16 at 12:12
  • can you change the names of those some colors and try again? – percusse Jun 20 '16 at 12:17

Do not say


You need to pick something other than \value and other than any other existing macro which you wish to later use, either implicitly or explicitly.

When you use \pgfmathsetmacro, TeX defines the macro to whatever you say, even if the macro already exists. I'm not sure what


is intended to do, but what it is doing is assigning the current value to the macro globally. This breaks all subsequent use of \value in the document. Since all cross-references depend on this, it naturally breaks all later cross-references.

When choosing macro names - especially when making them global - it is essential to either define them in a way which will include a check or check yourself that your choice of name is a safe one.

LaTeX's \newcommand and \newenvironment include checks, so do xparse's \NewDocumentCommand and \NewDocumentEnvironment. \def, \edef, \xdef, \gdef etc. do not and, hence, neither to the PGF commands which depend on them. These therefore require particular care and should be used only when the LaTeX alternatives are not an option.

For further explanation see my answer to a question about a different symptom of the same problem.

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.