fpantigny / nicematrix

The LaTeX package nicematrix
3 stars 1 forks source link

Adding diagbox feature to nicematrix #5

Open Basmah1961 opened 4 months ago

Basmah1961 commented 4 months ago

image

tabularray has a command \diagbox which allows for convenient placement of diagonal boxes. It might be good to add this command instead of using \CodeAfter and tikzpicture

\documentclass[11pt, a4paper]{article}

\usepackage{fancyhdr}
\pagestyle{empty}

\usepackage{tikz}

\usepackage{nicematrix}

\usepackage{tabularray}
\UseTblrLibrary{diagbox}

\begin{document}

\begin{NiceTabular}[hvlines, cell-space-limits=0pt]{l l l}

    & Beta
    & Gamma
    \\

    Epsilon
    & Zeta
    & Eta
    \\

    Iota
    & Kappa
    & Lambda
    \\

    \CodeAfter
    \begin{tikzpicture}[remember picture,overlay,outer sep=0pt,inner sep=0pt]

        \draw[] (1-|1)--(2-|2);

        \node[anchor=north east] at ([shift={(-1pt,-1pt)}] 1-|2) {Pp};

        \node[anchor=south west] at ([shift={(+1pt,+1pt)}] 2-|1) {Aa};

    \end{tikzpicture}

\end{NiceTabular}

\bigskip

\begin{tblr}{colspec={Q[l,h] Q[l,t] Q[l,h]},
        rowsep=0pt, 
        hlines,vlines
}

    \diagbox{Aa}{Pp}
    & Beta
    & Gamma
    \\

    Epsilon
    & Zeta
    & Eta
    \\

    Iota
    & Kappa
    & Lambda
    \\

\end{tblr}

\end{document}
fpantigny commented 4 months ago

nicematrix yet has such feature with its built-in command \diagbox.

\documentclass[11pt, a4paper]{article}
\pagestyle{empty}
\usepackage{nicematrix}

\begin{document}

\begin{NiceTabular}[hvlines]{l l l}
\diagbox{Aa}{Pp}
& Beta
& Gamma
\\

Epsilon
& Zeta
& Eta
\\

Iota
& Kappa
& Lambda
\\
\end{NiceTabular}

\end{document}

image

Basmah1961 commented 4 months ago

nicematrix yet has such feature with its built-in command \diagbox.

\documentclass[11pt, a4paper]{article}
\pagestyle{empty}
\usepackage{nicematrix}

\begin{document}

\begin{NiceTabular}[hvlines]{l l l}
\diagbox{Aa}{Pp}
& Beta
& Gamma
\\

Epsilon
& Zeta
& Eta
\\

Iota
& Kappa
& Lambda
\\
\end{NiceTabular}

\end{document}

image

I did not know it is available. However, I think it is possible to improve it by

  1. Adding customizable vertical white space above and below
  2. The arguments of diagbox (Aa and Pb) must have \tabcolsep margin from vertical rules
fpantigny commented 4 months ago

You are right. It's a good suggestion. However, I can't change easily such features without silently breaking existing documents. The command \diagbox has been introduced in the version 4.1 of 2020/05/27 (four years ago) and it's not so difficult for the final user to add a \hspace*{...} and a \strut (for the vertical space).

Basmah1961 commented 4 months ago

Then why not make \diagbox behave as normally does, but add an optional key to change its behavior? This way, existing documents will not be affected while users get to test new functionalities which emulate tabularray