![Tikz 日历风格](https://linux22.com/image/347625/Tikz%20%E6%97%A5%E5%8E%86%E9%A3%8E%E6%A0%BC.png)
我有一个简单的 Tikz 日历。
我只是想开始新的一周周日,这对我来说似乎更自然——也就是说,我希望星期日在左边。
在 MWE 之下:
\documentclass{article}
\usepackage[margin = 2.5cm, a4paper]{geometry}
\pagestyle{empty}
\usepackage[brazil]{babel}
\usepackage{fontspec}
\setmainfont{Alegreya Sans}
\usepackage{tikz}
\usetikzlibrary{calendar,positioning}
\def\pgfcalendarmonthname#1{ \translate{\ifcase#1\or Janeiro\or Fevereiro\or Março\or Abril\or Maio\or Junho\or Julho\or Agosto\or Setembro\or Outubro\or Novembro\or Dezembro\fi} }
\def\pgfcalendarmonthshortname#1{ \translate{\ifcase#1\or Jan\or Fev\or Mar\or Abr\or Mai\or Jun\or Jul\or Ago\or Set\or Out\or Nov\or Dez\fi} }
\def\pgfcalendarweekdayshortname#1{ \translate{\ifcase#1\or Seg\or Ter\or Qua\or Qui\or Sex\or Sab\or Dom\fi} }
\def\pgfcalendarweekdayname#1{ \translate{\ifcase#1\or Segunda\or Terça\or Quarta\or Quinta\or Sexta\or Sábado\or Domingo\fi} }
\newcommand{\calyear}{2017}
\newcommand{\mon}[1]{\calendar[dates = \calyear-#1-01
to \calyear-#1-last] if (Sunday) [red];}
\begin{document}
\begin{tikzpicture}[every calendar/.style = {
month label above centered,
month text = {\Large\textsc{\%mt}},
week list,
}]
\matrix (Calendar) [column sep = 4em, row sep = 3em] {
\mon{01} & \mon{02} & \mon{03} \\
\mon{04} & \mon{05} & \mon{06} \\
\mon{07} & \mon{08} & \mon{09} \\
\mon{10} & \mon{11} & \mon{12} \\ };
\node [above = 1cm of Calendar, font = \Huge]
{\calyear};
\end{tikzpicture}
\end{document}
答案1
集成macmadness86 的回答进入问题中的代码:
\documentclass{article}
\usepackage[margin = 2.5cm, a4paper]{geometry}
\pagestyle{empty}
\usepackage[brazil]{babel}
\usepackage{fontspec}
\setmainfont{Alegreya Sans}
\usepackage{tikz}
\usetikzlibrary{calendar,positioning}
\makeatletter
\tikzstyle{week list sunday}=[
% Note that we cannot extend from week list,
% the execute before day scope is cumulative
execute before day scope={%
\ifdate{day of month=1}{\ifdate{equals=\pgfcalendarbeginiso}{}{
% On first of month, except when first date in calendar.
\pgfmathsetlength{\pgf@y}{\tikz@lib@cal@month@yshift}%
\pgftransformyshift{-\pgf@y}
}}{}%
},
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=6
\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{Saturday}{
\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
\def\pgfcalendarmonthname#1{ \translate{\ifcase#1\or Janeiro\or Fevereiro\or Março\or Abril\or Maio\or Junho\or Julho\or Agosto\or Setembro\or Outubro\or Novembro\or Dezembro\fi} }
\def\pgfcalendarmonthshortname#1{ \translate{\ifcase#1\or Jan\or Fev\or Mar\or Abr\or Mai\or Jun\or Jul\or Ago\or Set\or Out\or Nov\or Dez\fi} }
\def\pgfcalendarweekdayshortname#1{ \translate{\ifcase#1\or Seg\or Ter\or Qua\or Qui\or Sex\or Sab\or Dom\fi} }
\def\pgfcalendarweekdayname#1{ \translate{\ifcase#1\or Segunda\or Terça\or Quarta\or Quinta\or Sexta\or Sábado\or Domingo\fi} }
\newcommand{\calyear}{2017}
\newcommand{\mon}[1]{\calendar[dates = \calyear-#1-01
to \calyear-#1-last] if (Sunday) [red];}
\begin{document}
\begin{tikzpicture}[every calendar/.style = {
month label above centered,
month text = {\Large\textsc{\%mt}},
week list sunday,
}]
\matrix (Calendar) [column sep = 4em, row sep = 3em] {
\mon{01} & \mon{02} & \mon{03} \\
\mon{04} & \mon{05} & \mon{06} \\
\mon{07} & \mon{08} & \mon{09} \\
\mon{10} & \mon{11} & \mon{12} \\ };
\node [above = 1cm of Calendar, font = \Huge]
{\calyear};
\end{tikzpicture}
\end{document}
答案2
开始使用此来源http://www.texample.net/tikz/examples/changing-the-default-calendar-layout/
Tikz 日历风格
% Define our own style
\tikzstyle{week list sunday}=[
% Note that we cannot extend from week list,
% the execute before day scope is cumulative
execute before day scope={%
\ifdate{day of month=1}{\ifdate{equals=\pgfcalendarbeginiso}{}{
% On first of month, except when first date in calendar.
\pgfmathsetlength{\pgf@y}{\tikz@lib@cal@month@yshift}%
\pgftransformyshift{-\pgf@y}
}}{}%
},
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=6
\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{Saturday}{
\pgfmathsetlength{\pgf@y}{\tikz@lib@cal@yshift}%
\pgftransformyshift{-\pgf@y}
}{}%
},
% This should be defined, glancing from the source code.
tikz@lib@cal@width=7
]
week list
用替换您的风格week list sunday
。
答案3
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{calendar, positioning}
\usepackage{xparse}
\NewDocumentCommand\mon{m O{\the\year}}
{
\calendar[
dates=#2-#1-1 to #2-#1-last, % date range
month label above centered, % month lable alignment
% get month short name
month text = {\textit{\pgfcalendarmonthshortname{\pgfcalendarcurrentmonth}}},
% if Sunday shift to left 1.5em otherwise move to the right 1.5em * weekday code (Monday = 0, ..., Saturday=6)
execute at begin day scope={ \ifdate{Sunday}{\pgftransformxshift{-1.5em}}{\pgftransformxshift{1.5*\pgfcalendarcurrentweekday em}}},
% if Saturday move down 1.2em to another line
execute after day scope={\ifdate{Saturday}{\pgftransformyshift{-1.2em}}{}},
% adjust month lable to the center
every month/.append style={xshift=3em},
% mark today
execute at begin day scope={\ifdate{equals=\year-\month-\day}{\draw[fill=green!30] (0,0) circle (8pt);}{}}]
if(Sunday) [red!50!black]
if(Saturday) [red!50!black];
}
\begin{document}
\begin{tikzpicture}[every day/.style={anchor=mid}]
\matrix (Calendar) [column sep = 2em, row sep = 3em] {
\mon{01} & \mon{02} & \mon{03} \\
\mon{04} & \mon{05} & \mon{06} \\
\mon{07} & \mon{08} & \mon{09} \\
\mon{10} & \mon{11} & \mon{12} \\};
\node [above=of Calendar, font=\Huge]{\the\year};
\end{tikzpicture}
\end{document}