0
\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}

Here is the output:

screenshot of my pdf

My question is why changing the \upperpadding variable does nothing. It does not give me an error. But it also does not change anything. Making it 0 or 20 does not matter. I believe the compiler is latexmk.

I am open to any other suggestions regarding this code. This is my first attempt. I may have overcomplicated things.

osbm
  • 137
  • 1
    If you move everything to a new y-coordinate, the same tikzpicture will be produced and inserted as normal at the same location(at \begin{tikzpicture}) in the document. For \upperpadding to make sense, you need something that is not moved. – hpekristiansen Jun 07 '23 at 21:54
  • 1
    Every TikZ picture has its own coordinate system and crops it's content. The coordinates can only be used to place things in relation to their picture not others or the page. Except when remember picture and the special current page is used. Quick fix would be to use \path(0,0); to make the origin actually part of your picture. (Or just use \vspace{\upperpadding} before the TikZ picture.) – Qrrbrbirlbel Jun 07 '23 at 21:54
  • 1
    You might be interested in the calendar library: Q407675 and many others. – Qrrbrbirlbel Jun 07 '23 at 21:59

1 Answers1

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}

As hpekristiansen and qrrbrbirlbel pointed out the tikz picture needed another node

osbm
  • 137