考虑一下 Tikz 日历的这种垂直排列。
我怎样才能将星期几的名称替换为大写字母?
\documentclass[12pt]{article}
\usepackage{tikz}
\usetikzlibrary{calendar}
\begin{document}
\begin{tikzpicture}
\calendar[dates=2021-01-01 to 2021-01-last,
day list downward,
day code={
\node[anchor = east]{\tikzdaytext};
\draw node[anchor = west, gray]{\pgfcalendarweekdayshortname{\pgfcalendarcurrentweekday}};
},
execute after day scope={
\ifdate{Sunday}{\pgftransformyshift{1em}}{}},
]
if(weekend) [shape=coordinate]; % (1)
\end{tikzpicture}
\end{document}
答案1
替换\pgfcalendarweekdayshortname
并将\myweekday
序言中的后者定义为
\newcommand\myweekday[1]{\ifcase#1M\or T\or W\or T\or F\or S\or S\fi}
\documentclass[12pt]{article}
\usepackage{tikz}
\usetikzlibrary{calendar}
\newcommand\myweekday[1]{\ifcase#1M\or T\or W\or T\or F\or S\or S\fi}
\begin{document}
\begin{tikzpicture}
\calendar[dates=2021-01-01 to 2021-01-last,
day list downward,
day code={
\node[anchor = east]{\tikzdaytext};
\draw node[anchor = west, gray]{\myweekday{\pgfcalendarcurrentweekday}};
},
execute after day scope={
\ifdate{Sunday}{\pgftransformyshift{1em}}{}},
]
if(weekend) [shape=coordinate]; % (1)
\end{tikzpicture}
\end{document}
答案2
\StrLeft
从包中使用xstring
:
\documentclass[12pt]{article}
\usepackage{tikz}
\usetikzlibrary{calendar}
\usepackage{xstring}
\begin{document}
\begin{tikzpicture}
\calendar[dates=2021-01-01 to 2021-01-last,
day list downward,
day code={
\node[anchor = east]{\tikzdaytext};
\draw node[anchor = west, gray]{\StrLeft{\pgfcalendarweekdayshortname{\pgfcalendarcurrentweekday}}{1}};
},
execute after day scope={
\ifdate{Sunday}{\pgftransformyshift{1em}}{}},
]
if(weekend) [shape=coordinate]; % (1)
\end{tikzpicture}
\end{document}