## LaTeX forum ⇒ Graphics, Figures & Tables ⇒ predefining colors in TikZ

Information and discussion about graphics, figures & tables in LaTeX documents.
Antoine C
Posts: 1
Joined: Thu Sep 22, 2016 6:11 pm

### predefining colors in TikZ

[This is my very first question, so please judge me charitably if I am not presenting it in the expected format!]

I am running into problem when using a color in TikZ which I have predefined using conditionals. The message I get is

Package pgfkeys Error: I do not know the key '/tikz/ green ' and I am going t
o ignore it. Perhaps you misspelled it.

In the minimal example below, the first call to TikZ works fine, but not the second. I tried using {...} but it doesn't seem to do anything.

\documentclass{minimal}\usepackage{tikz}\usepackage{xcolor}\begin{document}\def\mycolor#1{\ifnum#1=0green\elsered\fi}\def\somecolor{green}\tikz \fill[\somecolor](0,0) rectangle (1,1);\tikz \fill[\mycolor0](0,0) rectangle (1,1);\end{document}

Tags:

rais
Posts: 160
Joined: Sun Nov 16, 2014 8:51 pm
Welcome aboard

Your definition of \mycolor introduces whitespace at the end of the color name.
Without this space it works for me:
\documentclass{minimal}\usepackage{tikz}\def\mycolor#1{%   \ifnum#1=0     green%   \else     red%   \fi}\begin{document}\tikz \fill[\mycolor1](0,0) rectangle (1,1);\tikz \fill[\mycolor0](0,0) rectangle (1,1);\end{document}

KR
Rainer