Tikz 日历-如何使用'\def'传递参数

Tikz 日历-如何使用'\def'传递参数

给出以下代码

\documentclass[a4paper,20pt]{extarticle}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc} 
\usepackage[czech]{babel}
\usepackage[czech]{translator}
\usepackage{graphicx, comment, tikz}
\usetikzlibrary{calendar, shapes.misc} 
\usepackage{pgfkeys,pgfcalendar} 
\usepackage{geometry}
 \geometry{
 left=9mm,
 top=13mm,
 bottom=9mm,
 right=10mm
 }
\newcounter{tgmymo}
\setcounter{tgmymo}{0}
\newcommand{\mymo}[4]{%
    \begin{minipage}{\textwidth}%
        \centering%
        \stepcounter{tgmymo}
        \includegraphics[width=#4\textwidth]{#3}
    \end{minipage}
    
   \vfill

 \begin{center}
  {\textsc{\pgfcalendarmonthname{\value{tgmymo}}} 2024}
 \end{center}
    
    \vfill
    
    \noindent \begin{minipage}[t][10cm][t]{.99\textwidth}\centering
       \begin{tikzpicture}[thick]
    \pgfcalendar{cal}{#1}{#2}{%
        \ifdate{workday}%
        {\tikzset{filling/.style={fill=black!05}}}%
        {\tikzset{filling/.style={fill=orange!20}}}
        %%
        \def\normal{\node (\pgfcalendarsuggestedname) at (\pgfcalendarcurrentweekday*2.52,0) [filling, rectangle,rounded corners, text width=.105\textwidth,text height=9.796mm ,align=right] {\\ \pgfcalendarcurrentday};}%
        %%
       \def\bday#1{\node (\pgfcalendarsuggestedname) at (\pgfcalendarcurrentweekday*2.52,0) [filling, rectangle, rounded corners, text width=.105\textwidth,text height=9.796mm, align=right] {\\ \textcolor{red}{#1} \textcolor{red}{\pgfcalendarcurrentday}};}%
       
        %% birthdays will come here 
        \ifdate{equals=09-02}{\bday(mum)}{\normal}%
      


        %---end of birthdays     
        \ifdate{Sunday}{\pgftransformyshift{-2.35cm}}{}%
        };
        \end{tikzpicture}\end{minipage}
        \clearpage}
       
\begin{document}
\setlength\parindent{0pt}
\pagestyle{empty}
 \mymo{2024-01-01}{2024-01-last}{example-image}{.55}
 \mymo{2024-02-01}{2024-02-last}{example-image}{.9}
 \mymo{2024-03-01}{2024-03-last}{example-image}{.55}
 \mymo{2024-04-01}{2024-04-last}{example-image}{.55}
 \mymo{2024-05-01}{2024-05-last}{example-image}{.9}
 \mymo{2024-06-01}{2024-06-last}{example-image}{.9}
 \mymo{2024-07-01}{2024-07-last}{example-image}{.55}
 \mymo{2024-08-01}{2024-08-last}{example-image}{.6}
 \mymo{2024-09-01}{2024-09-last}{example-image}{.485}
 \mymo{2024-10-01}{2024-10-last}{example-image}{.55}
 \mymo{2024-11-01}{2024-11-last}{example-image}{.55}
 \mymo{2024-12-01}{2024-12-last}{example-image}{.475}
\end{document}

我希望\bday命令能够发挥作用。我想传递一个参数 - 生日那天的人的名字,但我不知道正确的语法。谢谢大家♥

答案1

让我们来看看...

  1. 用于\newcommand你的\normal\bday(它是 LaTeX;如果可以的话,尽量避免使用内部 TeX 的东西)。
  2. 当您调用时\bday使用{}来界定参数(不是())。
  3. 在顶层定义宏;可以在宏内定义宏,但在这里很棘手且没有必要。
  4. 我调整了宏\bday以产生两行输出思考您正在寻找的;不确定我是否理解正确。
\documentclass[a4paper,20pt]{extarticle}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[czech]{babel}
\usepackage[czech]{translator}
\usepackage{graphicx, comment, tikz}
\usetikzlibrary{calendar, shapes.misc}
\usepackage{pgfkeys,pgfcalendar}
\usepackage{geometry}
\geometry{ left=9mm, top=13mm, bottom=9mm, right=10mm }
\newcounter{tgmymo}
\setcounter{tgmymo}{0}
\newcommand\normal{%
    \node (\pgfcalendarsuggestedname) at (\pgfcalendarcurrentweekday*2.52,0) [filling, rectangle,rounded corners, text width=.105\textwidth,text height=9.796mm ,align=right] {\\ \pgfcalendarcurrentday};
}%
%%
\newcommand\bday[1]{%
    \node (\pgfcalendarsuggestedname) at (\pgfcalendarcurrentweekday*2.52,0) [filling, rectangle, rounded corners, text width=.105\textwidth,text height=9.796mm, align=right] { \textcolor{red}{#1}\\ \textcolor{red}{\pgfcalendarcurrentday}};
}%
\newcommand{\mymo}[4]{%
    \begin{minipage}{\textwidth}%
        \centering%
        \stepcounter{tgmymo}
        \includegraphics[width=#4\textwidth]{#3}
    \end{minipage}

    \vfill

    \begin{center}
        {\textsc{\pgfcalendarmonthname{\value{tgmymo}}} 2024}
    \end{center}

    \vfill

    \noindent
    \begin{minipage}[t][10cm][t]{.99\textwidth}
        \centering
        \begin{tikzpicture}[thick]
            \pgfcalendar{cal}{#1}{#2}{%
                \ifdate{workday}%
                    {\tikzset{filling/.style={fill=black!05}}}%
                    {\tikzset{filling/.style={fill=orange!20}}}
                    %%
                    %% birthdays will come here
                    \ifdate{equals=09-02}{\bday{mum}}{\normal}%



                    %---end of birthdays
                    \ifdate{Sunday}{\pgftransformyshift{-2.35cm}}{}%
                    };
                \end{tikzpicture}
            \end{minipage}
        \clearpage
}

\begin{document}
\setlength\parindent{0pt}
\pagestyle{empty}
\mymo{2024-01-01}{2024-01-last}{example-image}{.55}
\mymo{2024-02-01}{2024-02-last}{example-image}{.9}
\mymo{2024-03-01}{2024-03-last}{example-image}{.55}
\mymo{2024-04-01}{2024-04-last}{example-image}{.55}
\mymo{2024-05-01}{2024-05-last}{example-image}{.9}
\mymo{2024-06-01}{2024-06-last}{example-image}{.9}
\mymo{2024-07-01}{2024-07-last}{example-image}{.55}
\mymo{2024-08-01}{2024-08-last}{example-image}{.6}
\mymo{2024-09-01}{2024-09-last}{example-image}{.485}
\mymo{2024-10-01}{2024-10-last}{example-image}{.55}
\mymo{2024-11-01}{2024-11-last}{example-image}{.55}
\mymo{2024-12-01}{2024-12-last}{example-image}{.475}
\end{document}

在此处输入图片描述

答案2

改编

  • 定义命令\normal\bday在外部\mymo使用\newcommand
  • 此处使用花括号\bday{mum}
  • \bday在名称和日期之间添加换行符
  • 我将参数 1 和 2 合并\mymoyyyy-mm

代码

\documentclass[a4paper,20pt]{extarticle}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc} 
\usepackage[czech]{babel}
\usepackage[czech]{translator}
\usepackage{graphicx, comment, tikz}
\usetikzlibrary{calendar, shapes.misc} 
\usepackage{pgfkeys,pgfcalendar} 
\usepackage{geometry}
\geometry{
    left=9mm,
    top=13mm,
    bottom=9mm,
    right=10mm
}
\newcounter{tgmymo}
\setcounter{tgmymo}{0}

\newcommand{\normal}{%
    \node (\pgfcalendarsuggestedname) at (\pgfcalendarcurrentweekday*2.52,0) [filling, rectangle,rounded corners, text width=.105\textwidth,text height=9.796mm ,align=right] {\\ \pgfcalendarcurrentday};
}

\newcommand{\bday}[1]{%
    \node (\pgfcalendarsuggestedname) at (\pgfcalendarcurrentweekday*2.52,0) [filling, rectangle, rounded corners, text width=.105\textwidth,text height=9.796mm, align=right] {\textcolor{red}{#1}\\ \textcolor{red}{\pgfcalendarcurrentday}};
}

\newcommand{\mymo}[3]{%
    \begin{minipage}{\textwidth}%
        \centering%
        \stepcounter{tgmymo}
        \includegraphics[width=#3\textwidth]{#2}
    \end{minipage}
    
    \vfill
    
    \begin{center}
        {\textsc{\pgfcalendarmonthname{\value{tgmymo}}} 2024}
    \end{center}
    
    \vfill
    
    \noindent
    \begin{minipage}[t][10cm][t]{.99\textwidth}\centering
        \begin{tikzpicture}[thick]
            \pgfcalendar{cal}{#1-01}{#1-last}{%
                \ifdate{workday}%
                {\tikzset{filling/.style={fill=black!05}}}%
                {\tikzset{filling/.style={fill=orange!20}}}
                
                %% birthdays will come here 
                \ifdate{equals=09-02}{\bday{mum}}{\normal}%
                
                %---end of birthdays     
                \ifdate{Sunday}{\pgftransformyshift{-2.35cm}}{}%
            };
        \end{tikzpicture}
    \end{minipage}
    \clearpage
}

\begin{document}
\setlength\parindent{0pt}
\pagestyle{empty}
\mymo{2024-01}{example-image}{.55}
\mymo{2024-02}{example-image}{.9}
\mymo{2024-03}{example-image}{.55}
\mymo{2024-04}{example-image}{.55}
\mymo{2024-05}{example-image}{.9}
\mymo{2024-06}{example-image}{.9}
\mymo{2024-07}{example-image}{.55}
\mymo{2024-08}{example-image}{.6}
\mymo{2024-09}{example-image}{.485}
\mymo{2024-10}{example-image}{.55}
\mymo{2024-11}{example-image}{.55}
\mymo{2024-12}{example-image}{.475}
\end{document}

相关内容