目前我有一些使用 tikz 日历库的基本代码:
\usepackage{tikz}
\usetikzlibrary{calendar}
\tikz
\calendar [dates=2014-01-01 to 2014-1-last,
week list, month label above left]
if (Sunday) [red];
结果是:
有没有什么办法可以创建一个“两周列表”安排,以便我得到类似以下的内容,即将两个星期放在同一行?
答案1
您可以定义一个tikzstyle
来实现这一点。
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{calendar}
\makeatletter
\tikzstyle{biweek list}=[%
execute at begin day scope={%
\pgftransformyshift{-0.6cm}%
\pgfmathsetlength\pgf@x{\tikz@lib@cal@xshift}%
\pgf@x=\pgfcalendarcurrentweekday\pgf@x%
\pgftransformxshift{\pgf@x}%
\pgfmathsetlength\pgf@x{\tikz@lib@cal@xshift}%
\ifcsname pgfcalendarbiweek\endcsname%
\pgf@x=7\pgf@x%
\pgftransformxshift{\pgf@x}%
\fi%
},
execute after day scope={%
\ifdate{Sunday}{%
\ifcsname pgfcalendarbiweek\endcsname%
\let\pgfcalendarbiweek\undefined%
\pgfmathsetlength{\pgf@y}{\tikz@lib@cal@yshift}%
\pgftransformyshift{-\pgf@y}%
\else%
\let\pgfcalendarbiweek\relax%
\fi%
}{}%
},
execute at end day scope={%
\pgfmathsetlength\pgf@y{\tikz@lib@cal@yshift}%
\pgftransformyshift{1cm}%
}
]
\tikzoption{day headings}{\tikzstyle{day heading}=[#1]}
\tikzstyle{day heading}=[]
\tikzstyle{biweek day letter headings}=[
execute before day scope={%
\ifdate{day of month=1}{%
\pgftransformyshift{-1.6cm}%
\pgfmathsetlength\pgf@xa{\tikz@lib@cal@xshift}%
\pgfmathsetlength\pgf@y{\tikz@lib@cal@yshift}%
\pgftransformyshift{-0.6cm}%
\foreach \d/\l in {0/M,1/T,2/W,3/T,4/F,5/S}{%
\pgftransformxshift{\d\pgf@xa}%
\node[anchor=east,day heading]{\l};
\pgftransformxshift{7\pgf@xa}%
\node[anchor=east,day heading]{\l};
}%
{
\pgftransformxshift{6\pgf@xa}%
\node[anchor=east,day heading,red]{S};
\pgftransformxshift{7\pgf@xa}%
\node[anchor=east,day heading,red]{S};
}
}{}%
}%
]
\makeatother
\begin{document}
\tikz
\calendar[
dates=1997-06-01 to 1997-08-last,
biweek list,
biweek day letter headings,
month label above left,
month text=\bfseries\large\%mt \%y0
] if (Sunday) [red];
\end{document}
基于Jake 的解决方案。