1

My code is adapted primarily from Jake's answers verticle and weekday; as well as Berteun Damman's example.

Berteun Damman's line tiks@lib@cal@width=7 doesn't appear to make a difference so I have commented it out.

My goal is to make the date-numbers be red for odd-numbered days, and black for the rest.

Although this question addresses the same issue, I wasn't able to find the answer there. However, Stefan Kottwitz suggests using the if (odd) construction… but I haven't been able to make that work.

I have tried various variations of if (<date is odd>) [red] but have not been able to express <date is odd> correctly.

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{calendar}
\makeatletter
\tikzstyle{week list}=[
    execute before day scope={
        \ifdate{day of month=1}{\ifdate{equals=\pgfcalendarbeginiso}{}
            {% On first of month, except when first date in calendar.
            \pgfmathsetlength{\pgf@x}{\tikz@lib@cal@month@xshift}
            \pgftransformxshift{\pgf@x}
            }
        }{}
}, 
    execute at begin day scope={%
        \pgfmathsetlength\pgf@y{\tikz@lib@cal@yshift}%
        \pgf@y=\pgfcalendarcurrentweekday\pgf@y%
        \pgftransformyshift{-\pgf@y}%
        },
                      execute after day scope={%
        \ifdate{Sunday}{%
        \pgfmathsetlength{\pgf@x}{\tikz@lib@cal@xshift}%
        \pgftransformxshift{\pgf@x}
        }{}%
    },
    % % This should be defined according to Berteun (I don't know why.)
    % tikz@lib@cal@width=7
    %   ]
    ]

    \tikzoption{day headings}{\tikzstyle{day heading}=[#1]}
    \tikzstyle{day heading}=[]
    \tikzstyle{day letter headings}=[
    execute before day scope={ \ifdate{day of month=1}{%
        \pgfmathsetlength\pgf@ya{\tikz@lib@cal@yshift}%
        \pgfmathsetlength\pgf@xa{\tikz@lib@cal@xshift}%
        \pgftransformxshift{\pgf@xa}
        \foreach \d/\l in {0/Monday,1/Tuesday,2/Wednesday,3/Thursday,4/Friday,5/Saturday,6/Sunday} {
        \pgf@ya=\d\pgf@ya%
        \pgftransformxshift{-\pgf@xa}%
        \pgftransformyshift{-\pgf@ya}%
        \node[every day,day heading, anchor=base]{\l};%
            } 
        }{}%
    }%
]
\makeatother

\begin{document}
\tikz
\calendar
    [name=cal,
        dates=2018-02-01 to 2018-04-last,
        week list,
        day letter headings,
        day heading/.style={red, xshift=-1em},
        month label above centered,
        month text = \%y- \%mt \%y-,
        day xshift = 5ex,
        day yshift = 5ex,
        month yshift = 13ex
        ];
\end{document}
1

Add \ifodd\pgfcalendarcurrentday\relax \color{red} \fi to execute at begin day scope. The day of the month is contained in \pgfcalendarcurrentday and to check whether a number is odd in tex you can use \ifodd.

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{calendar}
\makeatletter
\tikzstyle{week list}=[
    execute before day scope={
        \ifdate{day of month=1}{\ifdate{equals=\pgfcalendarbeginiso}{}
            {% On first of month, except when first date in calendar.
            \pgfmathsetlength{\pgf@x}{\tikz@lib@cal@month@xshift}
            \pgftransformxshift{\pgf@x}
            }
        }{}
},
    execute at begin day scope={%
        \ifodd\pgfcalendarcurrentday\relax \color{red} \fi %%% <-- added line
        \pgfmathsetlength\pgf@y{\tikz@lib@cal@yshift}%
        \pgf@y=\pgfcalendarcurrentweekday\pgf@y%
        \pgftransformyshift{-\pgf@y}%
        },
                      execute after day scope={%
        \ifdate{Sunday}{%
        \pgfmathsetlength{\pgf@x}{\tikz@lib@cal@xshift}%
        \pgftransformxshift{\pgf@x}
        }{}%
    },
    % % This should be defined according to Berteun (I don't know why.)
    % tikz@lib@cal@width=7
    %   ]
    ]

    \tikzoption{day headings}{\tikzstyle{day heading}=[#1]}
    \tikzstyle{day heading}=[]
    \tikzstyle{day letter headings}=[
    execute before day scope={ \ifdate{day of month=1}{%
        \pgfmathsetlength\pgf@ya{\tikz@lib@cal@yshift}%
        \pgfmathsetlength\pgf@xa{\tikz@lib@cal@xshift}%
        \pgftransformxshift{\pgf@xa}
        \foreach \d/\l in {0/Monday,1/Tuesday,2/Wednesday,3/Thursday,4/Friday,5/Saturday,6/Sunday} {
        \pgf@ya=\d\pgf@ya%
        \pgftransformxshift{-\pgf@xa}%
        \pgftransformyshift{-\pgf@ya}%
        \node[every day,day heading, anchor=base]{\l};%
            }
        }{}%
    }%
]
\makeatother

\begin{document}
\tikz
\calendar
    [name=cal,
        dates=2018-02-01 to 2018-04-last,
        week list,
        day letter headings,
        day heading/.style={red, xshift=-1em},
        month label above centered,
        month text = \%y- \%mt \%y-,
        day xshift = 5ex,
        day yshift = 5ex,
        month yshift = 13ex
        ];
\end{document} 

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.