我想创建一个挂历,其中每页的底部都是一个tikzpicture
,将日期列表一直延伸到\linewidth
,就好像它是两端对齐的文本一样。
我如何设置日历样式,使xshift
日期恰好如此?我已达到您在下面看到的效果,但由于day xshift={0.0322\linewidth}
是固定的,因此它仅适用于 31 天的月份。
\documentclass[11pt]{article}
\usepackage[showframe]{geometry}
\usepackage{tikz}
\usetikzlibrary{calendar}
\setlength{\parindent}{0pt}
\pagestyle{empty}
\definecolor{gold}{RGB}{199,147,22}
\begin{document}
\raggedright
\makeatletter
\tikzset{
every calendar/.style={
day list right,
day xshift={0.0322\linewidth},
month text={\color{gold}\%mt \%y0},
month label above left,
execute at begin day scope={
\ifdate{Sunday}{\color{red}}
}
}
}
\makeatother
\raggedright
\tikz\calendar[dates=2013-01-01 to 2013-01-last];
\tikz\calendar[dates=2013-02-01 to 2013-02-last];
\tikz\calendar[dates=2013-03-01 to 2013-03-last];
\tikz\calendar[dates=2013-04-01 to 2013-04-last];
\tikz\calendar[dates=2013-05-01 to 2013-05-last];
\end{document}
答案1
您可以使用execute after day scope
执行一些代码来提取当前月份的天数并执行\pgftransformxshift
相应的操作:
\documentclass[11pt]{article}
\usepackage[showframe]{geometry}
\usepackage{tikz}
\usetikzlibrary{calendar}
\setlength{\parindent}{0pt}
\pagestyle{empty}
\definecolor{gold}{RGB}{199,147,22}
\begin{document}
\raggedright
\tikzset{
every calendar/.style={
day list right,
day xshift={0pt},
month text={\color{gold}\%mt \%y0},
month label above left,
execute at begin day scope={
\ifdate{Sunday}{\color{red}}
},
execute after day scope=
{
\pgfcalendarjuliantodate{\pgfcalendarendjulian}{\currentyear}{\currentmonth}{\lastday}
\pgftransformxshift{\textwidth/\lastday}
}
}
}
\tikz\calendar[dates=2013-01-01 to 2013-01-last];
\tikz\calendar[dates=2013-02-01 to 2013-02-last];
\tikz\calendar[dates=2013-03-01 to 2013-03-last];
\tikz\calendar[dates=2013-04-01 to 2013-04-last];
\tikz\calendar[dates=2013-05-01 to 2013-05-last];
\end{document}
如果您希望每一天之间的间隔相等(在这种情况下看起来更好),则需要进行更多的计算:
\documentclass[11pt]{article}
\usepackage[showframe]{geometry}
\usepackage{tikz,calc}
\usetikzlibrary{calendar}
\setlength{\parindent}{0pt}
\pagestyle{empty}
\definecolor{gold}{RGB}{199,147,22}
\begin{document}
\raggedright
\makeatletter
\tikzset{
every calendar/.style={
day list right,
day xshift={0pt},
month text={\color{gold}\%mt \%y0},
every month/.append style={inner xsep=0pt},
every day/.append style={anchor=east, inner xsep=0pt},
month label above left,
if=(Sunday) [red],
execute before day scope={
\ifdate{day of month=1}{
\pgftransformxshift{-\widthof{01}}
}{
\pgfcalendarjuliantodate{\pgfcalendarendjulian}{\currentyear}{\currentmonth}{\lastday}
\pgfmathparse{(\textwidth-\widthof{123456789}-\widthof{10111213141516171819202122232425262728}-\widthof{30}*(\lastday-28))/(\lastday-1)}
\pgftransformxshift{\pgfmathresult}
\let\%=\pgfcalendarshorthand
\setlength{\pgf@xc}{\widthof{\%d-}}
\pgftransformxshift{\pgf@xc}
}
}
}
}
\tikz\calendar[dates=2013-01-01 to 2013-01-last];
\tikz\calendar[dates=2013-02-01 to 2013-02-last];
\tikz\calendar[dates=2013-03-01 to 2013-03-last];
\tikz\calendar[dates=2013-04-01 to 2013-04-last];
\tikz\calendar[dates=2013-05-01 to 2013-05-last];
\end{document}