# Tikz calendar with week starting on Friday

I am trying to generate a calendar where the week starts on Friday, based on this example: http://www.texample.net/tikz/examples/changing-the-default-calendar-layout/

I am having trouble with Saturday and Sunday (shaded in grey) fitting in with the rest of the calendar. How can I move the weekend days to the second and third columns?

Here is my code:

% http://www.texample.net/tikz/examples/changing-the-default-calendar-layout/

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{calendar}

\makeatletter
% Define our own style
\tikzstyle{week list friday}=[
execute at begin day scope={%
% Because for TikZ Monday is 0 and Sunday is 6,
% we can't directly use \pgfcalendercurrentweekday,
% but instead we define \c@pgf@counta (basically) as:
% (\pgfcalendercurrentweekday + 1) % 7
\pgfmathsetlength\pgf@x{\tikz@lib@cal@xshift}%
\ifnum\pgfcalendarcurrentweekday=4
\c@pgf@counta=0
\else
\c@pgf@counta=\pgfcalendarcurrentweekday
\fi
\pgf@x=\c@pgf@counta\pgf@x
% Shift to the right position for the day.
\pgftransformxshift{\pgf@x}
},
execute after day scope={
% Week is done, shift to the next line.
\ifdate{Thursday}{
\pgfmathsetlength{\pgf@y}{\tikz@lib@cal@yshift}%
\pgftransformyshift{-\pgf@y}
}{}%
},
% This should be defined, glancing from the source code.
tikz@lib@cal@width=7
]
\makeatother

\begin{document}
\begin{tikzpicture}
\calendar[
dates=2010-04-01 to 2010-04-last,
if={(Saturday, Sunday) [black!50]},
week list friday,
];
\end{tikzpicture}
\end{document}


Seems that using

\pgfmathtruncatemacro{\tmp}{mod(\pgfcalendarcurrentweekday+3,7)}
\pgf@x=\tmp\pgf@x


instead of the \ifnum and counter stuff gives useful output.

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{calendar}

\makeatletter
% Define our own style
\tikzstyle{week list friday}=[
execute at begin day scope={%
% Because for TikZ Monday is 0 and Sunday is 6,
% we can't directly use \pgfcalendercurrentweekday,
% but instead we define \c@pgf@counta (basically) as:
% (\pgfcalendercurrentweekday + 1) % 7
\pgfmathsetlength\pgf@x{\tikz@lib@cal@xshift}%
\pgfmathtruncatemacro{\tmp}{mod(\pgfcalendarcurrentweekday+3,7)}
\pgf@x=\tmp\pgf@x
% Shift to the right position for the day.
\pgftransformxshift{\pgf@x}
},
execute after day scope={
% Week is done, shift to the next line.
\ifdate{Thursday}{
\pgfmathsetlength{\pgf@y}{\tikz@lib@cal@yshift}%
\pgftransformyshift{-\pgf@y}
}{}%
},
% This should be defined, glancing from the source code.
tikz@lib@cal@width=7
]
\makeatother

\begin{document}
\begin{tikzpicture}
\calendar[
dates=2010-04-01 to 2010-04-last,
if={(Saturday, Sunday) [black!50]},
week list friday,
];
\end{tikzpicture}
\end{document}