tikz 日历列表仅显示星期日

tikz 日历列表仅显示星期日

我想创建一个仅显示星期日的列表日历,并且能够注释该日期。

以下令人厌恶的黑客攻击有点接近我想要的,但是有许多弱点:

\documentclass{article}

\usepackage{tikz}

\usetikzlibrary{calendar}

\begin{document}

\begin{tikzpicture}
    \calendar [dates=2013-09-01 to 2013-12-last,
        day list downward, month yshift=1em, day yshift=.3em,
        month label left]
        if(Saturday,workday) [shape=coordinate]
        if (equals=2013-09-01) {\draw (0.5,0) node [anchor=west] {The first Sunday};}
        if (equals=2013-10-06) {\draw (0.5,0) node [anchor=west] {The first Sunday of October};};
\end{tikzpicture}

\end{document}
  1. 一定有更好的方法来仅显示周日。

  2. 在输出中,注释与日期数字没有相同的基线。

  3. 仅当该星期日恰好是该月的第一天时,该月第一个星期日才与月份标签对齐。

答案1

让我们介绍一种新样式sunday list downward。它很简单:只在星期日后向下移动。月份照常移动。

代码

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{calendar}
\makeatletter
\tikzset{sunday list downward/.style={%
  execute before day scope={
  \ifdate{day of month=1}{\ifdate{equals=\pgfcalendarbeginiso}{}
        {%
          \pgfmathsetlength{\pgf@y}{\tikz@lib@cal@month@yshift}%
          \pgftransformyshift{-\pgf@y}
        }%
      }{}%
  },
  execute after day scope={
  \ifdate{Sunday}{%
          \pgfmathsetlength{\pgf@y}{\tikz@lib@cal@yshift}%
          \pgftransformyshift{-\pgf@y}
      }{}%
  },
  tikz@lib@cal@width=1,
  if={(Sunday) [] else [shape=coordinate]}
}}
\makeatother
\tikzset{
    @annote/.style={
        every day/.append style={
            label={[text depth=+.5pt]right:{#1}}
        }
    },
    annote/.style args={#1with#2}{
        if={(equals=#1)[@annote={#2}]}
    },
    annote*/.style args={#1with#2}{
        if={(equals=#1){\annote[]{#2}}}
    }
}
\newcommand*{\annote}[2][]{\node[anchor=base west,at={(0.5,0)},#1] {#2};}
\begin{document}

\begin{tikzpicture}[label distance=.5cm]
    \calendar [dates=2013-09-01 to 2013-12-last,
        sunday list downward,
        day yshift=1.2\baselineskip,
        month yshift=1\baselineskip,
        month label left,
        annote=2013-09-01 with The first Sunday,
        annote=2013-10-06 with The first Sunday of October,
        annote*=2013-10-13 with Yet another Sunday in October
        ];
\end{tikzpicture}
\end{document}

输出

在此处输入图片描述

相关内容