0

I am preparing the academic calendar for my institution. It typically looks like the following: enter image description here I will create a tabular to fit the data. I have managed to generate the dates by a counter. What I need now is a cyclic counter for the days. I want to type \day[starting day of the month] in the first row, and \day in the successive rows. It should thus generate the entire second column as shown in the above picture. Please help me to achieve that. Following is the code I am working with.

\documentclass[9pt, twoside]{scrartcl}
\usepackage[cmyk]{xcolor}
\usepackage[paperwidth=108mm, paperheight=140mm, top=15mm, bottom=15mm, left=15mm, right=15mm, foot=2.5mm, head=2.5mm, showframe, marginparsep=0mm]{geometry}
\usepackage{fontspec}
\setmainfont{Latin Modern Roman}
\setsansfont{Latin Modern Sans}
\renewcommand{\familydefault}{\sfdefault}
\usepackage{titlesec}

\makeatletter \titleformat{\section}[runin]{}{}{0pt}{@gobble} \titleformat{\subsection}[runin]{}{}{0pt}{@gobble} \makeatother \titlespacing{\section}{0pt}{-\baselineskip}{0} \titlespacing{\subsection}{0pt}{-\baselineskip}{0}

\usepackage{fancyhdr, extramarks} \pagestyle{fancy} \fancyhf{}

\renewcommand{\sectionmark}[1]{\markboth{#1}{}} \renewcommand{\subsectionmark}[1]{\markright{#1}} \fancyhead[LE]{\color{cyan}\leftmark~|~\lastrightmark~|~Academic Calendar 2022-23} \fancyhead[RO]{\color{cyan}Academic Calendar 2022-23~|~\lastrightmark~|~\leftmark} \usepackage{hyperref} \usepackage{ragged2e} \usepackage{array, longtable} \parindent0pt \parskip0pt \usepackage{etoolbox} \newcounter{magicrownumbers} \newcommand\Rownum{\stepcounter{magicrownumbers}\arabic{magicrownumbers}} \preto\table{\setcounter{magicrownumbers}{0}} \preto\tabular{\setcounter{magicrownumbers}{0}} % % % \begin{document} \thispagestyle{empty} \vspace*{\fill} \begin{center} {\Large\color{cyan}Academic Calendar\2022-23} \end{center} \vfill \newpage \section{July} \subsection{Sonada} % \begin{center} \begin{tabular}{rlll} \Rownum. & Mon & Type & Content\ %Want to replace "Mon" by "\day[starting day of the month]" \Rownum. & Tue & Type & Content %Want to replace "Tue" by "\day" \end{tabular} \end{center} \newpage \subsection{Siliguri} % \begin{center} \begin{tabular}{rlll} \Rownum. & Mon & Type & Content\ %Want to replace "Mon" by "\day[starting day of the month]" \Rownum. & Tue & Type & Content %Want to replace "Tue" by "\day" \end{tabular} \end{center} % \end{document}

PS: I will be extra grateful if you please also guide me about how to type the first 9 dates as "01" till "09". Right now it prints "1" till "9".

2 Answers2

1

In this demo I only give 3 days of week instead of 7. Modify as you want.

Use a mixture of expl3 programming and plain-TeX programming (and needless to say, LaTeX2-style (what's this called?) programming for the counters). Read interface3.pdf and TeXbook/TeX by Topic and the LaTeX companion/unofficial LaTeX2e reference manual for the documentation of commands respectively (alternatively just search around on the site, although some might not have).

Also LaTeX already have a \day command, I use \dayz here

%! TEX program = lualatex

% ** search for "begin insertion" below to see the code. OP gives MWE too long...

\documentclass[9pt, twoside]{scrartcl} \usepackage[cmyk]{xcolor} \usepackage[paperwidth=108mm, paperheight=140mm, top=15mm, bottom=15mm, left=15mm, right=15mm, foot=2.5mm, head=2.5mm, showframe, marginparsep=0mm]{geometry} \usepackage{fontspec} \setmainfont{Latin Modern Roman} \setsansfont{Latin Modern Sans} \renewcommand{\familydefault}{\sfdefault} \usepackage{titlesec}

\makeatletter \titleformat{\section}[runin]{}{}{0pt}{@gobble} \titleformat{\subsection}[runin]{}{}{0pt}{@gobble} \makeatother \titlespacing{\section}{0pt}{-\baselineskip}{0} \titlespacing{\subsection}{0pt}{-\baselineskip}{0}

\usepackage{fancyhdr, extramarks} \pagestyle{fancy} \fancyhf{}

\renewcommand{\sectionmark}[1]{\markboth{#1}{}} \renewcommand{\subsectionmark}[1]{\markright{#1}} \fancyhead[LE]{\color{cyan}\leftmark~|~\lastrightmark~|~Academic Calendar 2022-23} \fancyhead[RO]{\color{cyan}Academic Calendar 2022-23~|~\lastrightmark~|~\leftmark} \usepackage{hyperref} \usepackage{ragged2e} \usepackage{array, longtable} \parindent0pt \parskip0pt \usepackage{etoolbox} \newcounter{magicrownumbers} \newcommand\Rownum{\stepcounter{magicrownumbers}\arabic{magicrownumbers}} \preto\table{\setcounter{magicrownumbers}{0}} \preto\tabular{\setcounter{magicrownumbers}{0}} % % % \begin{document} \thispagestyle{empty} \vspace*{\fill} \begin{center} {\Large\color{cyan}Academic Calendar\2022-23} \end{center} \vfill \newpage \section{July}

% ======== begin insertion \ExplSyntaxOn \newcounter{dayofweek} % 0: sun, 1: mon, ... \NewDocumentCommand \dayz {o} { \IfValueTF {#1} { \setcounter {dayofweek} { \str_case:nn {#1} { {Sun} {0} {Mon} {1} {Tue} {2} } } } { \stepcounter{dayofweek} \ifnum \value{dayofweek} = 3 \setcounter{dayofweek} {0} \fi % wrap around 3 → 0. }

\ifcase \value{dayofweek}
    Sun \or Mon \or Tue  % just for demo.
\fi

}

\ExplSyntaxOff % ======== end insertion

\subsection{Sonada} % \begin{center} \begin{tabular}{rlll} \Rownum. & \dayz[Mon] & Type & Content\ %Want to replace "Mon" by "\day[starting day of the month]" \Rownum. & \dayz & Type & Content %Want to replace "Tue" by "\day" \end{tabular} \end{center} \newpage \subsection{Siliguri} % \begin{center} \begin{tabular}{rlll} \Rownum. & \dayz[Mon] & Type & Content\ %Want to replace "Mon" by "\day[starting day of the month]" \Rownum. & \dayz & Type & Content %Want to replace "Tue" by "\day" \end{tabular} \end{center} % \end{document}

user202729
  • 7,143
  • Thanks much. Apologies for a late response. Out of the two working answers I had to choose the other one as it solved the PS question as well. However, yours did teach me how to create a cyclic counter. – Subhajit Paul Jun 20 '22 at 18:35
0

You also can use pgfcalendar:

\documentclass[9pt, twoside]{scrartcl}
\usepackage[cmyk]{xcolor}
\usepackage[paperwidth=108mm, paperheight=140mm, top=15mm, bottom=15mm, left=15mm, right=15mm, foot=2.5mm, head=2.5mm, showframe, marginparsep=0mm]{geometry}
\usepackage{fontspec}
\setmainfont{Latin Modern Roman}
\setsansfont{Latin Modern Sans}
\renewcommand{\familydefault}{\sfdefault}
\usepackage{titlesec}

\makeatletter \titleformat{\section}[runin]{}{}{0pt}{@gobble} \titleformat{\subsection}[runin]{}{}{0pt}{@gobble} \makeatother \titlespacing{\section}{0pt}{-\baselineskip}{0} \titlespacing{\subsection}{0pt}{-\baselineskip}{0}

\usepackage{fancyhdr, extramarks} \pagestyle{fancy} \fancyhf{}

\renewcommand{\sectionmark}[1]{\markboth{#1}{}} \renewcommand{\subsectionmark}[1]{\markright{#1}} \fancyhead[LE]{\color{cyan}\leftmark~|~\lastrightmark~|~Academic Calendar 2022-23} \fancyhead[RO]{\color{cyan}Academic Calendar 2022-23~|~\lastrightmark~|~\leftmark} \usepackage{hyperref} \usepackage{ragged2e} \usepackage{array, longtable} \parindent0pt \parskip0pt \usepackage{etoolbox} \newcounter{magicrownumbers} \newcommand\Rownum{\stepcounter{magicrownumbers}\ifnum\value{magicrownumbers}<10 0\fi\arabic{magicrownumbers}} \preto\table{\setcounter{magicrownumbers}{0}} \preto\tabular{\setcounter{magicrownumbers}{0}} % % % \newcount\myjdate \newcount\myweekday \newcounter{tmpmyjdate} \newcounter{tmpmyweekday} \usepackage{pgfcalendar} \def\wday#1{% \pgfcalendardatetojulian{#1}{\myjdate}% \setcounter{tmpmyjdate}{\the\myjdate}% \pgfcalendarjuliantoweekday{\thetmpmyjdate}{\myweekday}% \setcounter{tmpmyweekday}{\the\myweekday}% \nwday% } \def\nwday{% \ifcase\value{tmpmyweekday} Mon\or Tue\or Wen\or Thu\or Fri\or Sat\or Sun\fi\relax% \stepcounter{tmpmyjdate}\relax% \pgfcalendarjuliantoweekday{\thetmpmyjdate}{\myweekday}% \setcounter{tmpmyweekday}{\the\myweekday}% }

\begin{document} \thispagestyle{empty} \vspace*{\fill} \begin{center} {\Large\color{cyan}Academic Calendar\2022-23} \end{center} \vfill \newpage \section{July} \subsection{Sonada} \begin{center} \begin{tabular}{rlll} \Rownum. & \wday{2022-07-01} & Type & Content\ \Rownum. & \nwday & Type & Content\ \Rownum. & \nwday & Type & Content\ \Rownum. & \nwday & Type & Content\ \Rownum. & \nwday & Type & Content\ \Rownum. & \nwday & Type & Content\ \Rownum. & \nwday & Type & Content\ \Rownum. & \nwday & Type & Content\ \Rownum. & \nwday & Type & Content\ \Rownum. & \nwday & Type & Content\ \Rownum. & \nwday & Type & Content\ \Rownum. & \nwday & Type & Content \end{tabular} \end{center} \newpage \subsection{Siliguri} % \begin{center} \begin{tabular}{rlll} \Rownum. & \wday{2022-07-01} & Type & Content\ \Rownum. & \nwday & Type & Content\ \Rownum. & \nwday & Type & Content\ \end{tabular} \end{center} % \end{document}

Tom
  • 7,318
  • 4
  • 21