3

I am curious, since I have done several tests, how to set up the square brackets for the first matrix when I use the border with spalign package. I have seen this question and....actually I am not able to do it.

Better spacing around brackets of kbordermatrix

\documentclass[a4paper,12pt]{article}
\usepackage{spalign}
\begin{document}
\[\def\spalignendline{\cr}
\spalignrun{\bordermatrix{\the\spaligntoks}}
{, \scriptstyle{1} \scriptstyle{2}; \scriptstyle{1} 0 1; \scriptstyle{2} 1 0}\times \spaligndelims{[}{]} \spalignmat{a b; c d}=\spaligndelims{\{}{\}} \spalignmat{r t; s w}\]
\end{document}

enter image description here

Sebastiano
  • 54,118
  • @campa Hiii :-)...and thank you very much for your comment. I not know it. But after 8 years and 10 months ago, do I must necessary to use modification of \bordermatrix? sigh sigh....But in spalign package is recent...So is this package obsolete? – Sebastiano Mar 05 '21 at 13:05
  • @campa spalign package. I have seen the documentation...October 5, 2016. See § 3 Implementation pag. 10. – Sebastiano Mar 05 '21 at 13:08
  • 1
    I wouldn't say it's obsolete. It looks like it's been loaded on CTAN and never modified, so maybe it's unmantained, but it seems to be still working (I didn't know it so I have no experience with it). Regarding \bordermatrix: that's a plain TeX macro which has been copied into LaTeX and it will be likely never be modified. I see no trouble with making a copy changing the brackets, though I'd define my own version with interchangeable delimiters. But as you might have noticed I tend to use very few packages and write my own macros. – campa Mar 05 '21 at 13:14
  • 1
    Wouldn't nicematrix be better? – egreg Mar 05 '21 at 14:16
  • @egreg Surely with nicematrix, but... I wanted get another answer using spalign package. The answer with nicematrix has been put from the maintainer of the package. – Sebastiano Mar 05 '21 at 21:00

2 Answers2

3

The parentheses are hard-coded in \bordermatrix. You could define a version with brackets explicitly as shown in \bordermatrix with brackets [ ] instead of parentheses ( ).

Alternatively, let us be lazy, copy the definition of \bordermatrix, and let xpatch replace the parentheses by brackets.

\documentclass[a4paper,12pt]{article}
\usepackage{spalign}

\usepackage{xpatch} \let\bbordermatrix\bordermatrix \xpatchcmd{\bbordermatrix}{(}{[}{}{} \xpatchcmd{\bbordermatrix}{)}{]}{}{}

\begin{document} [ \def\spalignendline{\cr}\spaligndelims{[}{]} \spalignrun{\bbordermatrix{\the\spaligntoks}} {, \scriptstyle{1} \scriptstyle{2}; \scriptstyle{1} 0 1; \scriptstyle{2} 1 0} \times \spaligndelims{[}{]} \spalignmat{a b; c d} = \spaligndelims{{}{}} \spalignmat{r t; s w} ] \end{document}

enter image description here

campa
  • 31,130
3

For information, in nicematrix, you can easily write a command \lightmatrix to compose matrices with the syntax of spalign (thanks to the key light-syntax inspired by spalign) with the ability to use all the features of nicematrix, included exterior rows and columns (inspired by \bordermatrix and kbordermatrix).

\documentclass{article}
\usepackage{nicematrix}

\begin{document}

\ExplSyntaxOn \NewDocumentCommand { \lightmatrix } { D < > { p } O { } m } { \group_begin: \NiceMatrixOptions { light-syntax } \begin { #1 NiceMatrix} [ #2 ] #3 \end { #1 NiceMatrix } \group_end: } \ExplSyntaxOff

\NiceMatrixOptions { code-for-first-row = \scriptstyle, code-for-first-col = \scriptstyle, }

$\lightmatrix<b>[first-row,first-col]{ {} 1 2 ; 1 0 1 ; 2 1 0 } \times \lightmatrix{a b ; c d} = \lightmatrix<B>{r t ; s w}$

\end{document}

Output of the above code

F. Pantigny
  • 40,250
  • Very nice answer ..but you first matrix have not the square brackets with the labels out the matrix. – Sebastiano Mar 05 '21 at 21:02
  • 1
    @Sebastiano: You are right. I have modified my answer. – F. Pantigny Mar 05 '21 at 21:06
  • Ah, don't worry. Please, what is the code to have the square brackets? – Sebastiano Mar 05 '21 at 21:10
  • 1
    \lightmatrix{...} for rounded brackets (the default value), \lightmatrix<b>{...} for the square brackets, \lightmatrix{B} for curly braces, etc. – F. Pantigny Mar 05 '21 at 21:14
  • Thank you very much...and I have given a suggestion for a your recent answer. Excuse me with all my heart...but I give the check mark to @campa because is very closer to my question. But...I have given my grazie in another forms. – Sebastiano Mar 05 '21 at 21:18