Need a way to nest line breaks in tabularx environment for Calendar

Course Queries Syllabus Queries 2 years ago

0 1 0 0 0 tuteeHUB earn credit +10 pts

5 Star Rating 1 Rating

Posted on 16 Aug 2022, this text provides information on Syllabus Queries related to Course Queries. Please note that while accuracy is prioritized, the data presented might not be entirely correct or up-to-date. This information is offered for general knowledge and informational purposes only, and should not be considered as a substitute for professional advice.

Take Quiz To Earn Credits!

Turn Your Knowledge into Earnings.

tuteehub_quiz

Answers (1)

Post Answer
profilepic.png
manpreet Tuteehub forum best answer Best Answer 2 years ago


I am trying to make an academic calendar package. I know there's a veritable horde of them out there and I've looked through many of them but can't seem to find one I like. Since I am (usually) pretty competent with LaTeX, I figured I would just write my own. This has led to a mildly annoying issue that should be an easy fix but I can't seem to get there.

The Relevant Commands:

Right now I have the calendar being generated fine minus a small issue when trying to populate a day on the calendar. I will include all of the .sty file at the bottom, but it's quite long and pretty hacky still (still writing the rough draft), so I will extract the important parts here;

The calendar is (purposely) pre-populated, with each day having it's own command for it's contents, then I defined a "DayContent" command to renew the relevent day's command to populate the desired content (ideally I'd actually populate the calendar by building a conditional that checks if a command has been defined for that day, and if not, it would populate it with the default blank dated tile). The command is as follows:

\newcommand{\dayContent}[3]{% This puts content on the given day of the calendar.
                        % Syntax: \dayContent{Month}{Day}{Agenda}
                        %       Renews the content of the command for day "Day" and month "Month" to display "Agenda"
\expandafter\def\csname calendarDay#2Month#1\endcsname{%
    {\raggedleft #2}% We want dates in the top right corner
    \scriptsize #3% Calendars are small, write inside it small.
    \refstepcounter{dayVal}
}%

}

After I have generated the necessary commands and determined what months are going to be displayed (all in the termCalendar.sty code below) I use a printCalendar command to then print everything;

\newcommand{\printCalendar}{% The user command to make the calendar
\monthLabel
\setcounter{monthMax}{\arabic{MonthOne}}% Start with the first Month
\stepcounter{curMonthNum}% Step counter to get the right number of days
\begin{center}
{\large \bfseries \curMonthText}% Print month's name at head
\end{center}
\begin{tabularx}{\textwidth}{|l|X|X|X|X|X|r|}% Print Month's Calendar Heading
\hline \textbf{Sun}& \textbf{Monday}& \textbf{Tuesday}& \textbf{Wednesday}& \textbf{Thursday}& \textbf{Friday}& \textbf{Sat}\\ \hline\hline
\genFirstWeek% This will generate the first week, we need to be careful about semesters where the month ends in the same week the semester starts.
\genLastWeek\\ \hline% In this case we only need a first and last week Otherwise there would be as many \genFullWeek commands between the genFirst and genLast as we need.
\end{tabularx}
\stepcounter{monthVal}

\genFirstWeek\genLastWeek commands are basically just wrappers to check some conditionals and populate the weeks as needed depending on what day of the week the first day of the month and last day of the month land on.

The Problem:

Everything populates great, except that if I want to have multiple lines on a given calendar day, they get indented and I can't seem to eliminate the indent no matter what I do.

(Following Text in [ ] is no longer accurate, See Edit Below; No longer using a nested tabular environment as the line break doesn't break tabularx) [I need to contain the linebreak in something so that the line break doesn't percolate out into the tabularx environment and generate errors. Currently I'm doing this by trying to wrap the contents in a tabular environment (thus nesting a tabular environment inside the tabularx environment) which ... kind of works.]

eg, I use the following code for the first day of classes:

\dayContent{8}{22}{
First Day Of Class\\
\textbf{Intro \& Syllabus}}

The problem is, it has a small indent that I can't get rid of no matter what. (No longer relevant text in [ ]) [You might see the @{} above, which was a solution I tried to pull from here, but it doesn't seem to work (and I don't understand it at all... does it need a \makeatletter? Because the answer suggests no, but it doesn't work either way). Regardless, the nested tabular environment was because] I couldn't figure out how to get minipage working in any way that made sense... ideally I'd love each calendar day cell to be it's own minipage, but I have no idea how to do that.

(\raggedleft issue resolved by David Carlisle, see comments below) Also, a much less important but somewhat irksome point; the \raggedleft command above doesn't seem to get the calendar's date number in the top right as I thought it would. Any suggestions on how to fix that? And any idea why it doesn't work?

To be clear, I could probably hack at this and get something that works, but I am actually more curious as to why this indent is there, even after things like \noindent and even \hspace{(negative length)} are added. I don't really know how indentation works in LaTeX at a basic/primative level other than that it saves some "length" values somewhere and uses those somehow... but the mechanics elude me. If there are any references to read about this, I would reallyappreciate links to them in addition to any answers.

Thanks!

EDIT As was pointed out by David Carlisle in the comments below, it turns out that tabularx makes p-columns and thus supports line breaks. Fortunately this means I can ditch the nested tabular environment. Unfortunately I still get the same exact behavior, ie the small indent at the start of each line inside the calendar day's cell.

As promised; the full sty code:

%
% Tex Type: Latex2e
\NeedsTeXFormat{LaTeX2e}
% Provides Package:
\ProvidesClass{termCalendar}

% Required Packages for this style file
\RequirePackage{tabularx}
\RequirePackage{ifthenx}
\RequirePackage{forloop}
\RequirePackage[margin=1in]{geometry
                                                
                                                
0 views
0 shares

No matter what stage you're at in your education or career, TuteeHub will help you reach the next level that you're aiming for. Simply,Choose a subject/topic and get started in self-paced practice sessions to improve your knowledge and scores.