0

I am preparing the academic calendar for my institution. It typically looks like the following: enter image description here

As you can see, I need to create 24 tables like this. I will create tabular to fit the data. Each table will contain around 28 - 36 rows. What I am looking here for is to be able to modify the \arraystretch component automatically so that the total table height is same as the \textheight. I do not want to use the resizebox or adjustbox as it will mess with the font size in each page. The following MWE contains the information about the font and page sizes, and is motivated from this answer to my question posted earlier.

\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}
    \def\arraystretch{1}% <== need to adjust this automatically
        \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\\
            \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\\ 
            \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}

The MWE is agreeably a little long to provide more information as to avoid any possible clash with the commands or packages.

EDIT: (10.06.2024) Solution to the problem with wrapping cells is given here.

4

1 Answer 1

2
+50

Here is a solution with tabularray package and three remarks:

  1. the \textheight is so small that the page can not include 28 rows, so you need to decrease document font size first.

  2. there are some vertical shift in the second page, which is caused by the \section commnad, so you need to adjust it.

  3. the tabularray.sty in your Overleaf project is a little old, please download the latest one (version 2022B) from CTAN.

\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}
\parindent0pt
\parskip0pt

\selectcolormodel{natural}
\usepackage{ninecolors}
\selectcolormodel{rgb}
\usepackage{tabularray}
\UseTblrLibrary{counter}
\SetTblrInner[tblr]{rowsep=0pt,stretch=0}
\newcounter{magicrownumbers}
\newcommand\Rownum{\ifnum\value{rownum}<10 0\fi\arabic{rownum}}
\newcommand\calcrowht{%
  \dimexpr
    (
      \textheight
       %- 0.4pt * ( \value{rowcount} + 1) % hrule sizes
    ) / \value{rowcount}
  \relax
}

\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{tblr}[t]{colspec={rlll},rows={ht=\calcrowht},row{even}={gray9},row{odd}={azure9}}
            \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\\
            \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\\
%            \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{tblr}
    \newpage
\subsection{Siliguri}
    \begin{tblr}{colspec={rlll},rows={ht=\calcrowht},row{even}={gray9},row{odd}={azure9}}
            \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{tblr}
\end{document}

enter image description here

3
  • Thank you so much for your answer and comments. May I ask the last favour please! Can you please fix the columnwidths in the following way: First and second columns will be as they appear in the above code. The longest word in the third column will be "Class". The fourth column will have the rest of the spaces and the contents in that column should wrap if needed. The entire width of the table will be same as \textwidth. Thank you. Commented Jun 24, 2022 at 12:31
  • @SubhajitPaul Sorry, I can do it if the text wrap.
    – L.J.R.
    Commented Jun 24, 2022 at 12:57
  • Okay. I guess in that case, I have to manually wrap the text into the next line. Thanks for your help so far. Commented Jun 24, 2022 at 16:07

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .