改变盒子位置没有任何作用

改变盒子位置没有任何作用
\documentclass{article}
\usepackage[a4paper,landscape,margin=0.5in]{geometry}
\usepackage{tikz}

\begin{document}
\thispagestyle{empty}
\begin{center}
    \huge
    % January - 2023
    \begin{tikzpicture}[scale=0.8, every node/.style={scale=0.8}]
        \def\daywidth{4cm}
        \def\dayheight{3cm}
        \def\boxsize{1.75ex}
        \def\boxsep{0.4ex}
        \def\upperpadding{1.5cm}
        \def\monthname{January}
        \def\year{2023}
        \def\startday{6} % Adjust this value to change the starting day of the week (0 - Sunday, 1 - Monday, etc.)
        \def\numdays{31} % Adjust this value based on the actual number of days in the month
        
        \def\daynames{{"Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"}}
        % \node[anchor=north west] at (0.5*\daywidth*\numdays,0.5*\dayheight) {\monthname \ \year};

        \foreach \day in {0,1,...,6} {
            \node[anchor=north west, minimum width=\daywidth, minimum height=\boxsize, text depth=\boxsep, align=center,draw] at (30+\daywidth*\day, -\upperpadding) {\pgfmathparse{\daynames[\day]}\pgfmathresult};
        }

        % draw the empty boxes for the days before the first day of the month
        \foreach \day in {1,...,\startday} {
            \node[anchor=north west, minimum width=\daywidth, minimum height=\dayheight, text depth=\boxsep, align=center, draw] at (30+\daywidth*\day-\daywidth, -\upperpadding-3*\boxsize) {};
        }

        \foreach \d in {1,...,\numdays} {
            \pgfmathsetmacro{\dy}{int((\d-1+\startday)/7)}
            \pgfmathsetmacro{\dx}{mod(\d-1+\startday,7)}

            \node[anchor=north west,minimum width=\daywidth,minimum height=\dayheight,draw] at (30+\dx*\daywidth,-\upperpadding-\dy*\dayheight- 3*\boxsize) {\d};
        }
    \end{tikzpicture}
\end{center}
\end{document}

输出如下:

我的 pdf 截图

我的问题是为什么改变\upperpadding变量没有任何作用。它没有给我错误。但它也没有改变任何东西。将其设置为 0 或 20 都无所谓。我相信编译器是latexmk

我愿意听取有关此代码的任何其他建议。这是我的第一次尝试。我可能把事情搞得太复杂了。

答案1

\documentclass{article}
\usepackage[a4paper,landscape,margin=0.5in]{geometry}
\usepackage{tikz}
\usepackage{lmodern}
\begin{document}
\thispagestyle{empty}
\begin{center}
    \huge
    \begin{tikzpicture}[scale=0.8, every node/.style={scale=0.8}]
        \def\daywidth{4cm}
        \def\dayheight{3cm}
        \def\boxsize{1.75ex}
        \def\boxsep{0.5ex}
        \def\upperpadding{2.6cm}
        \def\monthname{January}
        \def\year{2023}
        \def\startday{6} % Adjust this value to change the starting day of the week (0 - Sunday, 1 - Monday, etc.)
        \def\numdays{31} % Adjust this value based on the actual number of days in the month
        \def\daynames{{"Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"}}
        
        \node[anchor=north,align=center,font=\fontsize{30}{30}\selectfont] at (0.5\textwidth,-1cm) {\monthname \ \year};

        \foreach \day in {0,1,...,6} {
            \node[anchor=north, minimum width=\daywidth, minimum height=\boxsize, text depth=\boxsep, align=center,draw] at (30+\daywidth*\day, -\upperpadding) {\pgfmathparse{\daynames[\day]}\pgfmathresult};
        }

        \foreach \day in {1,...,\startday} {
            \node[anchor=north, minimum width=\daywidth, minimum height=\dayheight, text depth=\boxsep, align=center, draw] at (30+\daywidth*\day-\daywidth, -\upperpadding-3*\boxsize) {};
        }

        \foreach \d in {1,...,\numdays} {
            \pgfmathsetmacro{\dy}{int((\d-1+\startday)/7)}
            \pgfmathsetmacro{\dx}{mod(\d-1+\startday,7)}

            \node[anchor=north,minimum width=\daywidth,minimum height=\dayheight,draw] at (30+\dx*\daywidth,-\upperpadding-\dy*\dayheight- 3*\boxsize) {\d};
        }

    \end{tikzpicture}
\end{center}
\end{document}

作为赫佩克里斯蒂安森qrrbrbirlbel指出 tikz 图片需要另一个节点

相关内容