在 Tikz 日历中自定义日期名称

在 Tikz 日历中自定义日期名称

考虑一下 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)是忽略周末的一个伎俩。
MWE 捕获

答案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}

在此处输入图片描述

相关内容