4

I want to create a table that looks like

enter image description here

I used the nicematrix package and was able to create something like this

enter image description here

I found that it is hard to add rules inside a matrix environment. Here is my code:

\begin{equation*}
  \begin{matrix}
    \begin{matrix}
       \\ a \\ a \\ a \\ a \\ a \\ a \\ a \\ a
    \end{matrix} &
    \begin{NiceMatrix}[first-row]
      r & \xi_1-\xi_2 & \xi_3-\xi_2 \\
      b & c & d \\ 
      b & c & d \\ 
      b & c & d \\ 
      b & c & d \\ 
      b & c & d \\ 
      b & c & d \\ 
      b & c & d \\ 
      b & c & d \\ 
      b & c & d
    \end{NiceMatrix}
  \end{matrix}
\end{equation*}

I think using equation environments to create a table might cause some unexpected errors. Also, it is inconvenient to add rules. Even with this answer I still find it difficult to customize the rules. Are there any alternatives?

2 Answers 2

6

Here is a solution with nicematrix.

\documentclass{article}
\usepackage{nicematrix,tikz}

\usepackage{collcell}


\ExplSyntaxOn

\cs_new_protected:Nn \__Huang_cell:nn 
  { \tikz \node [anchor=center] at (#1-|1.5) { $#2$ } ; }

\NewDocumentCommand{\Cell}{m}
  { 
    \int_compare:nNnTF { \arabic{iRow} } = 0 
      { #1 }
      {
        \tl_gput_right:Nx \g_nicematrix_code_after_tl 
          {  \__Huang_cell:nn { \int_eval:n { \arabic{iRow} + 1 } } { #1 } }
      }
  }

\ExplSyntaxOff

\begin{document}

\NiceMatrixOptions{cell-space-limits=3pt}

\begin{equation*}
\begin{NiceArray}[first-row]{>{\collectcell{\Cell}}w{c}{1cm}<\endcollectcell|c|c|c|}
         &  r & \xi_1-\xi_2 & \xi_3-\xi_2 \\
x        &  \Block[hvlines]{*-*}{}
            b & c & d \\ 
         &  b & c & d \\ 
a        &  b & c & d \\ 
a        &  b & c & d \\ 
a        &  b & c & d \\ 
a+b      &  b & c & \dfrac{d}{e} \\ 
a        &  b & c & d \\ 
x        &  b & c & d \\ 
         &  b & c & d
\CodeAfter
  \tikz \foreach \x in {1,...,9} \draw (\x.5-|1) -- (\x.5-|2) ; 
  \tikz \draw (1.5-|1) -- (\arabic{iRow}.5-|1) ; 
\end{NiceArray}
\end{equation*}

\end{document}

Output of the above code

4

This is an exercise for proper use of \hbox, \vbox, \hrule, and \vrule primitives:

\def\mb#1{\hbox to2.5em{\vrule height1.2em depth.5em\hss#1\hss}}
\def\mt#1{\hbox to2.5em{\hss$\scriptstyle#1$\hss}}
\let\hr=\hrule

\vbox{
   \hbox{\mt{\Delta r}\mt{r}\mt{\xi_1-\xi_2}\mt{\xi_3-\xi_4}}
   \smallskip
   \hbox{\offinterlineskip
     \raise 1.3ex\vbox{\hr\mb{a}\hr\mb{a}\hr\mb{a}\hr\mb{A}\hr}%
     \vbox{\hr\mb{b}\mb{b}\mb{b}\mb{b}\mb{B}\hr}%
     \vbox{\hr\mb{c}\mb{c}\mb{c}\mb{c}\mb{C}\hr}%
     \vbox{\hr\mb{d}\mb{d}\mb{d}\mb{d}\mb{D}\hr}%
     \vrule
}}
0

You must log in to answer this question.

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