7

Possible Duplicates:
How to submit a set of tikz command with pgfkeys?
Multiple TikZ keys with foreach

I have a class file which is supposed to modify the maketitle. I use TikZ nodes for placement of elements, and wish to add a background for one of the text nodes.

If I add the options directly, everything works fine:

\node [text width=40mm,fill=red] {Foo}

However, since I want to give class users the option to turn the background coloring off, I want to give those node options as a macro, which has a different value depending on class options:

\newcommand\nodefillstyle{fill=red}

\node [text width=40mm,\nodefillstyle] {Foo}

I would expect this to work just as it works elsewhere, but it fails with a confusing error message:

! Package pgfkeys Error: I do not know the key '/tikz/fill=red' and I am going 
to ignore it. Perhaps you misspelled it.

Below you can see my class file and .tex file:

test-article.cls:

\NeedsTeXFormat{LaTeX2e}
\ProvidesClass{test-article}[2013/01/02 My test documentclass]

% Use article default options
\DeclareOption*{\PassOptionsToClass{\CurrentOption}{article}}
\ProcessOptions

\LoadClass{article}

\RequirePackage{tikz}

\newcommand\nodestyle{fill=red}

\renewcommand\maketitle{%
 \begin{tikzpicture}%
  \node [text width=40mm,\nodestyle] at (current page.center) {\@title};%
 \end{tikzpicture}%
}

simplefill.tex:

\documentclass[a4paper]{test-article}

\title{My title}

\begin{document}
 \maketitle
\end{document}

Why does this happen, and how can I achieve using macros within node options?

  • 3
    This looks quite like a duplicate of http://tex.stackexchange.com/q/85637/86 (which was really a duplicate of http://tex.stackexchange.com/q/64137/86). – Andrew Stacey Jan 08 '13 at 11:16
  • Thank you Andrew, http://tex.stackexchange.com/questions/64137/multiple-tikz-keys-with-foreach duplicates this issue, and has the correct answer to it as well. The macro expansion dilemma is more generic issue but not necessary for solving this problem as tikzstyles applied conditionally are more elegant solution. – Jukka Dahlbom Jan 08 '13 at 12:25
  • That's great that the other questions provide enough for you to work with. To help others find them more quickly, we'll close this one as a duplicate as that makes the search more efficient. – Andrew Stacey Jan 08 '13 at 12:27
  • (To those who can vote to close as a duplicate) I've gone for 85637 as the duplicate as I think that that one provides the cleaner answer to the question of expanding macros in pgfkeys. That it often isn't necessary is good to know but sometimes one does want to do this and someone reading this question should be directed to that solution, I think. But we can always put both in the "duplicate of" text. – Andrew Stacey Jan 08 '13 at 12:29

0 Answers0