![在 Tikz 日历中自定义日期名称](https://linux22.com/image/439638/%E5%9C%A8%20Tikz%20%E6%97%A5%E5%8E%86%E4%B8%AD%E8%87%AA%E5%AE%9A%E4%B9%89%E6%97%A5%E6%9C%9F%E5%90%8D%E7%A7%B0.png)
考虑一下 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}