Tikz 日历,一周从星期五开始

Tikz 日历,一周从星期五开始

我正在尝试根据以下示例生成一个日历,其中一周从星期五开始: http://www.texample.net/tikz/examples/changing-the-default-calendar-layout/

我无法将星期六和星期日(灰色阴影)与日历的其他部分对齐。我怎样才能将周末移至第二列和第三列?

在此处输入图片描述

这是我的代码:

% 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
            \advance\c@pgf@counta by 1
        \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}

答案1

似乎使用

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

而不是\ifnum和计数器的东西给出有用的输出。

代码输出

\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}

相关内容