I'm very used to come here often to debug my code and find solutions to my problem. But it's the first time i cannot find a solution to my exact problem or something i could adapt for my case. So here i am with my question. Sorry in advance if my wording is not perfect, i'm not a TeX expert but rather an enthusiast.
I am currently writing a .cls class file to write my reports. I renew the maketitle command to create my cover page. There are 2 tables i want to fill automatically. A MWE example
My main tex file is built as follows:
\documentclass{MyClass}
\revision{
2015-03-31 & John Doe\\ \hline
2015-04-01 & Jane Doe\\ \hline
& \\ \hline
}
\diffusion{%
Company A & John Doe\\ \hline
Company B & Jane Doe\\ \hline
}
\begin{document}
\maketitle
\end{document}
I use the commands \revision and \diffusion to pass the content of the table into my class file. The class is built as follows:
% My class
\NeedsTeXFormat{LaTeX2e}
\ProvidesClass{MyClass}[my beautiful class]
\LoadClass[11pt]{article}
\DeclareOption*{\PassOptionsToClass{\CurrentOption}{article}}
\ProcessOptions\relax
% -- Some packages
\RequirePackage{lmodern}
\RequirePackage[T1]{fontenc}
\RequirePackage[utf8]{inputenc}
\RequirePackage[english,french]{babel}
\RequirePackage{array,tabularx,hhline}
\RequirePackage{graphicx,colortbl,import}
\RequirePackage[dvipsnames,table]{xcolor}
\RequirePackage{geometry}
\RequirePackage{nicematrix}
\RequirePackage{tabularray}
\RequirePackage{makecell}
\definecolor{softgray}{gray}{0.9}
\newcommand{\revision}[1]{\def\nt@revision{#1}}
\newcommand{\diffusion}[1]{\def\nt@diffusion{#1}}
\geometry{a4paper,twoside,pdftex,
lmargin=1.91cm,
rmargin=1.91cm,
tmargin=4cm,
headheight=24mm,
textheight=22cm,
headsep=0.5cm,
footskip=0.5cm
}
\renewcommand{\arraystretch}{1.5}
\renewcommand{\maketitle}{
\pagestyle{plain}
\section*{Revision}
\noindent
\begin{NiceTabularX}{\textwidth}{|l|X|}[colortbl-like]
\hline
\rowcolor{softgray} Date & Author \\ \hline
\nt@revision
\end{NiceTabularX}
% Not working starting from here
\section*{Diffusion}
\noindent
\begin{tblr}{
colspec = {|l|X|},
rowspec={Q[m]Q[m]Q[m]Q[m]Q[m]Q[m]Q[m]Q[m]Q[m]Q[m]},
rowsep = 3pt,
width = \textwidth,
}
\hline
\SetCell{bg=softgray}\textbf{Company} & \SetCell{bg=softgray}\textbf{Name} \\ \hline
\nt@revision
\end{tblr}
}
The tables need to have the first row with a gray background. I had issues with pdf viewers where the border lines of the tables would disappear (covered by the background color). I could find partial solution here.
- I found on this website that i could use NiceTabularX with the option [colortbl-like] to avoid the problem of the lines disappearing. It works (see the table built in the \section*{Revision}). However, i have to call pdfLaTeX 3 or 4 times for the table to appear finally properly. Is this normal ? Is there a workaround ?
- I found that it works better with tabularray. However, i have an error. Somehow, the parameter \nt@revision is not passed properly. I do not understand what is happening ?
- Is there something i missed, a better solution to do what i want to do ?
Thanks in advance for your help.
tblr
to expand\nt@revision
:\begin{tblr}[expand=\nt@revision]{
nicematrix
, it's normal to have to do several compilations withnicematrix
. However, there are several tools, such aslatexmk
which determine the right number of compilations for you.