3

I'd like to create a style with parameters for use with the TikZ calendar library.

Here's a working example similar to what I want:

\documentclass[10pt]{article}
\usepackage{tikz}
\usetikzlibrary{calendar}

\begin{document}
\tikzstyle{ColorDay}=[if={(equals=2-7) [every day/.append style=#1]}]

\begin{tikzpicture}
    \calendar (cal) [dates=2013-02-1 to 2013-02-28,week list,
    ColorDay={red}];
\end{tikzpicture}
\end{document}

I have two problems.

First, I am forced to use the deprecated \tikzstyle command here, instead of \tikzset. I can't get \tikzset to work at all with calendar if's. For instance,

\tikzset{ColorDay/.style=if={(equals=2-7) [every day/.append style=#1]}}

doesn't work. In fact, it doesn't work even if I remove the parameter.

\tikzset{ColorDay/.style=if={(equals=2-7) [every day/.append style=red]}}

Second, I don't know how to create a style with multiple parameters. For instance,

\tikzstyle{ColorDay}=[if={(equals=#1) [every day/.append style=#2]}]

doesn't work.

1
  • 1
    Welcome to TeX.SX! You can have a look on our starter guide to familiarize yourself further with our format.
    – Corentin
    May 29, 2013 at 17:22

1 Answer 1

5

\tikzset does work here, but you need to use a set of braces if the style contains commas or equal signs. To get a style with two arguments, use \tikzset{Color Day/.style 2 args={...}}, or if you want even more arguments, use \tikzset{Color Day/.style n args={3}{...}}:

\documentclass[10pt]{article}
\usepackage{tikz}
\usetikzlibrary{calendar}

\begin{document}
\tikzset{
    ColorDay/.style 2 args={
        if={(equals=#1) [every day/.append style=#2]}
    }
}

\begin{tikzpicture}
    \calendar (cal) [dates=2013-02-1 to 2013-02-28,week list,
    ColorDay={2-7}{red},
    ColorDay={2-16}{blue, font=\bfseries}];
\end{tikzpicture}
\end{document}
1
  • @user31463: That's great! In that case, you can upvote and accept the answer by clicking the upward pointing triangle and the tick mark next to it. That will close the question.
    – Jake
    May 30, 2013 at 19:12

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .