Tikz 日历月份标签未出现

Tikz 日历月份标签未出现

如果二月从月初开始,则会出现月份标签;否则不会出现:

\documentclass{article}
\usepackage[margin = 2.5cm, a4paper]{geometry}
\pagestyle{empty}
\usepackage[brazil]{babel}
\usepackage{fontspec}
\setmainfont{Alegreya Sans}
\usepackage{tikz}
\usetikzlibrary{calendar,positioning,shapes}


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

\tikzstyle{xis}=[cross out, draw,thick,draw=red!50,very thick]


\begin{document}
\noindent
\begin{tikzpicture}
[every day/.style={anchor=mid},every node/.style={inner sep=2pt,rectangle,thick},gray]
\calendar (cal) [dates=2019-02-22 to 2019-06-14, 
%month list, 
%month label left,%
week list,%
month label above centered,%
month text=\textcolor{black}{\%mt},
%every month/.append style={anchor=base east, 
%xshift=-2em},
month yshift=2em,
every month/.append style={yshift=-5em,xshift=-8em}
]
%
%if (Tuesday) [black]
%if (Friday) [black]
if (Sunday) [red]
if (Saturday) [blue]
if (Friday) [black,nodes={thick,draw=red!50}]
if (equals=2019-03-15) [nodes={cross out,draw,very thick}]
if (equals=2019-04-19) [nodes={cross out,draw,very thick}]
;
\end{tikzpicture}

\medskip 

\tikz[baseline=-3pt] \node[xis] at (0,0) {15/03};~~~Semana dos calouros

\medskip 

\tikz[baseline=(char.base)]{ \node[xis] (char) at (0,0) {19/04};}~~~ Sexta-Feira Santa

%don't know which baseline is better, left both options


\end{document}

我还做了一些奇怪的调整以使月份保持对齐:

every month/.append style={yshift=-5em,xshift=-8em}

或许对此有更好的选择。

答案1

月份文本仅在每个月的第一天添加,但可以添加其他文本:

\documentclass{article}
\usepackage[margin = 2.5cm, a4paper]{geometry}
\pagestyle{empty}
\usepackage[brazil]{babel}
%\usepackage{fontspec}
%\setmainfont{Alegreya Sans}
\usepackage{tikz}
\usetikzlibrary{calendar,positioning,shapes}


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

\tikzstyle{xis}=[cross out, draw,thick,draw=red!50,very thick]


\begin{document}
\noindent
\begin{tikzpicture}
[every day/.style={anchor=mid},every node/.style={inner sep=2pt,rectangle,thick},gray,
]
\calendar (cal) [dates=2019-02-22 to 2019-06-14, 
%month list, 
%month label left,%
week list,%
month label above centered,%
month text=\textcolor{black}{\%mt},
%every month/.append style={anchor=base east, 
%xshift=-2em},
month yshift=2em,
every month/.append style={yshift=-5em,xshift=-8em},
execute at begin day scope=
{
    \ifdate{equals=2019-02-22}{
        \node at (-8em,0em) [anchor=base east] {\small\tikzmonthtext};
    }{}
},
]
%
%if (Tuesday) [black]
%if (Friday) [black]
if (Sunday) [red]
if (Saturday) [blue]
if (Friday) [black,nodes={thick,draw=red!50}]
if (equals=2019-03-15) [nodes={cross out,draw,very thick}]
if (equals=2019-04-19) [nodes={cross out,draw,very thick}]
;
\end{tikzpicture}

\medskip 

\tikz[baseline=-3pt] \node[xis] at (0,0) {15/03};~~~Semana dos calouros

\medskip 

\tikz[baseline=(char.base)]{ \node[xis] (char) at (0,0) {19/04};}~~~ Sexta-Feira Santa

%don't know which baseline is better, left both options


\end{document}

在此处输入图片描述

相关内容