aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--weekschedule.cls65
1 files changed, 32 insertions, 33 deletions
diff --git a/weekschedule.cls b/weekschedule.cls
index db9be2e..9b387ee 100644
--- a/weekschedule.cls
+++ b/weekschedule.cls
@@ -41,32 +41,37 @@
\newcommand{\@hourheight}{1.5}
\newcommand{\@padding}{0.08}
+% Time label configuration
+\newcommand{\@timelabelxpos}{-0.1} % X position of time labels
+\newcommand{\@timelabelreserved}{1.5} % Space reserved for time labels
+
% Week configuration
-\newcommand{\@weektype}{workweek} % workweek, fullweeksunday, fullweekmonday
\newcommand{\@weekdaylist}{Monday,Tuesday,Wednesday,Thursday,Friday}
-\newcommand{\@weekdaydisplay}{Monday,Tuesday,Wednesday,Thursday,Friday}
\newcommand{\@daycount}{5}
% Minute line configuration
\newcommand{\@minutelineinterval}{0} % 0=off, 30=half-hour, 15=quarter-hour
+% Spacing constants
+\newcommand{\@titlespace}{0.05cm}
+\newcommand{\@legendspace}{0.2cm}
+\newcommand{\@dayheaderoffset}{0.2} % Vertical offset for day headers
+
% ============================================
% User-facing configuration commands
% ============================================
\newcommand{\scheduletitle}[1]{\renewcommand{\@scheduletitle}{#1}}
\newcommand{\scheduleauthor}[1]{\renewcommand{\@scheduleauthor}{#1}}
-% Parse time string like "8:00" or "13:30" and store hour
+% Parse time string like "8:00" or "13:30" and store hour (integer part only)
\newcommand{\timefrom}[1]{%
\@parsetime{#1}%
- \pgfmathtruncatemacro{\@temph}{\@parsedtime}%
- \edef\@starthour{\@temph}%
+ \pgfmathtruncatemacro{\@starthour}{\@parsedtime}%
}
\newcommand{\timeto}[1]{%
\@parsetime{#1}%
- \pgfmathtruncatemacro{\@temph}{\@parsedtime}%
- \edef\@endhour{\@temph}%
+ \pgfmathtruncatemacro{\@endhour}{\@parsedtime}%
}
% Time format toggles
@@ -75,23 +80,17 @@
% Week configuration toggles
\newcommand{\weekworkweek}{%
- \renewcommand{\@weektype}{workweek}%
\renewcommand{\@weekdaylist}{Monday,Tuesday,Wednesday,Thursday,Friday}%
- \renewcommand{\@weekdaydisplay}{Monday,Tuesday,Wednesday,Thursday,Friday}%
\renewcommand{\@daycount}{5}%
}
\newcommand{\weekfullsunday}{%
- \renewcommand{\@weektype}{fullweeksunday}%
\renewcommand{\@weekdaylist}{Sunday,Monday,Tuesday,Wednesday,Thursday,Friday,Saturday}%
- \renewcommand{\@weekdaydisplay}{Sunday,Monday,Tuesday,Wednesday,Thursday,Friday,Saturday}%
\renewcommand{\@daycount}{7}%
}
\newcommand{\weekfullmonday}{%
- \renewcommand{\@weektype}{fullweekmonday}%
\renewcommand{\@weekdaylist}{Monday,Tuesday,Wednesday,Thursday,Friday,Saturday,Sunday}%
- \renewcommand{\@weekdaydisplay}{Monday,Tuesday,Wednesday,Thursday,Friday,Saturday,Sunday}%
\renewcommand{\@daycount}{7}%
}
@@ -119,7 +118,6 @@
% Event class definitions (colors)
% ============================================
\newcounter{@numclasses}
-\setcounter{@numclasses}{0}
\newcounter{@daypos}
% Define an event class with RGB color
@@ -157,13 +155,13 @@
\LARGE\textbf{\@scheduletitle}%
\ifx\@scheduleauthor\empty\else\\[0.2cm]\Large\@scheduleauthor\fi%
\end{center}
- \vspace{0.05cm}
+ \vspace{\@titlespace}
\centering
\begin{tikzpicture}[x=1cm, y=1cm]
% Calculate dynamic day width based on number of days
- % Reserve 1.5cm for time labels, divide remaining width by day count
- \pgfmathsetmacro{\availablewidth}{(\textwidth/1cm) - 1.5}
+ % Reserve space for time labels, divide remaining width by day count
+ \pgfmathsetmacro{\availablewidth}{(\textwidth/1cm) - \@timelabelreserved}
\pgfmathsetmacro{\daywidth}{\availablewidth / \@daycount}
% Store other parameters
@@ -172,17 +170,14 @@
\pgfmathtruncatemacro{\starthour}{\@starthour}
\pgfmathtruncatemacro{\endhour}{\@endhour}
- % Calculate grid width (used later for drawing)
+ % Calculate grid width (used for drawing)
\pgfmathsetmacro{\gridwidth}{\@daycount*\daywidth}
% Calculate shift to center the grid properly
% \centering centers the bounding box, which includes time labels extending left.
- % The bounding box center is approximately at (-1.5 + gridwidth)/2.
- % The grid center is at gridwidth/2.
- % To align grid center with bounding box center (which is at page center),
- % shift right by: gridwidth/2 - (-1.5 + gridwidth)/2 = 1.5/2 = 0.75cm
- \pgfmathsetmacro{\timelabelreserved}{1.5}
- \pgfmathsetmacro{\xshift}{\timelabelreserved/2}
+ % To align grid center with bounding box center (which is at page center),
+ % shift right by half the reserved time label space.
+ \pgfmathsetmacro{\xshift}{\@timelabelreserved/2}
% Shift everything to align grid center with page center
\begin{scope}[xshift=\xshift cm]
@@ -190,22 +185,22 @@
% Draw column headers (days) - iterate through configured day list
\setcounter{@daypos}{0}
\@for\@currentday:=\@weekdaylist\do{%
- \node[anchor=south, font=\large\bfseries] at (\the@daypos*\daywidth+\daywidth/2, -\starthour*\hourheight+0.2) {\@currentday};
+ \node[anchor=south, font=\large\bfseries] at (\the@daypos*\daywidth+\daywidth/2, -\starthour*\hourheight+\@dayheaderoffset) {\@currentday};
\stepcounter{@daypos}%
}
% Draw row headers (times)
\foreach \hour in {\starthour,...,\endhour} {
- \pgfmathtruncatemacro{\displayhour}{mod(\hour-1,12)+1}
\if@usetwentyfourhour
- \node[anchor=east, font=\small] at (-0.1, -\hour*\hourheight) {\hour:00};
+ \node[anchor=east, font=\small] at (\@timelabelxpos, -\hour*\hourheight) {\hour:00};
\else
+ \pgfmathtruncatemacro{\displayhour}{mod(\hour-1,12)+1}
\ifnum\hour<12
\def\@ampm{AM}
\else
\def\@ampm{PM}
\fi
- \node[anchor=east, font=\small] at (-0.1, -\hour*\hourheight) {\displayhour:00 \@ampm};
+ \node[anchor=east, font=\small] at (\@timelabelxpos, -\hour*\hourheight) {\displayhour:00 \@ampm};
\fi
}
@@ -215,7 +210,6 @@
}
% Draw horizontal lines (hour separators)
- \pgfmathsetmacro{\gridwidth}{\@daycount*\daywidth}
\foreach \hour in {\starthour,...,\endhour} {
\draw[gray] (0, -\hour*\hourheight) -- (\gridwidth, -\hour*\hourheight);
}
@@ -246,16 +240,21 @@
\end{tikzpicture}
\par
- \vspace{0.2cm}
+ \vspace{\@legendspace}
% Legend
\begin{center}
\begin{tikzpicture}
+ \pgfmathsetmacro{\@legendspacing}{3.5} % Horizontal spacing between legend items
+ \pgfmathsetmacro{\@legendboxwidth}{0.4} % Width of legend color box
+ \pgfmathsetmacro{\@legendboxheight}{0.3} % Height of legend color box
+ \pgfmathsetmacro{\@legendtextoffset}{0.5} % Offset from box to text
+ \pgfmathsetmacro{\@legendycenter}{0.15} % Vertical center of legend items
\foreach \clnum in {1,...,\the@numclasses} {
- \pgfmathsetmacro{\xpos}{(\clnum-1)*3.5}
+ \pgfmathsetmacro{\xpos}{(\clnum-1)*\@legendspacing}
\edef\@clname{\csname @classname\clnum\endcsname}
- \fill[class@\@clname] (\xpos,0) rectangle (\xpos+0.4,0.3);
- \node[anchor=west] at (\xpos+0.5,0.15) {\@clname};
+ \fill[class@\@clname] (\xpos,0) rectangle (\xpos+\@legendboxwidth,\@legendboxheight);
+ \node[anchor=west] at (\xpos+\@legendtextoffset,\@legendycenter) {\@clname};
}
\end{tikzpicture}
\end{center}