2

I'm wondering if anyone can help me typeset this border matrix with lines inside it. Dashed or solid lines are okay but I would prefer the lines to not extend past the brackets. I would also prefer to not need to load 3+ packages to get this to happen.

I have tried several other solutions I've found on StackExchange but they don't seem to work (I don't have kbordermatrix and nicematrix doesn't draw lines for some reason).

Any advice is appreciated.

illustration

EDIT: Here's my current code:

\bbordermatrix{
              & {\bf 1}        & {\bf 5}        & {\bf 2}     & {\bf 4}        & {\bf 3} \cr
    {\bf 1}\, & \nicefrac16    & \nicefrac56    & 0           & 0              & 0 \cr
    {\bf 5}\, & \nicefrac16    & \nicefrac56    & 0           & 0              & 0 \cr
    {\bf 2}   & 0              & 0              & \nicefrac23 & \nicefrac13    & 0 \cr
    {\bf 4}   & 0              & 0              & \nicefrac23 & \nicefrac13    & 0 \cr
    {\bf 3}   & \nicefrac1{36} & \nicefrac5{36} & \nicefrac59 & \nicefrac5{18} & 0
    }

I've started to troubleshoot what's going wrong with NiceMatrix. I have a header file that I include as \include{...}. Something in that header file seems to make this matrix (source: bordermatrix with blocks):

nicegood

come out like this:

nicebad

The problem is, I went through and commented out every line of code in that header and nothing seems to specifically be the problem. In fact, if I don't include the header but just copy in every line, when I typeset the document the matrix first comes out wrong, but the second time I typeset it comes out right. I've never seen this sort of behavior before... how can I get different results?

Then if I remove the lines of the header file and replace them with \include, I get the reverse behavior: the first time it will typeset correctly, and all subsequent times it will typeset incorrectly.

I have no idea what's going on.

2
  • 1
    Welcome to TeX.SE. If possible, could you edit into your question the code you have been working on with nicematrix that doesn't work please? It just helps people if there is a basis point. The author of nicematrix is often on this site so I am sure he would like to know why it isn't working, perhaps there is a bug in the code or something is missing from your attempt etc., it would be really helpful and would help people help you easier.
    – JamesT
    Oct 23, 2022 at 21:33
  • Answer updated with the bold face. Oct 24, 2022 at 13:16

1 Answer 1

4

Here is a solution using nicematrix and two custom rules.

b

\documentclass[12pt,a4paper]{article}

\usepackage{xfrac} % nice fractions

\usepackage{nicematrix}
\usepackage{tikz}

\begin{document}
    
\NiceMatrixOptions
{
    custom-line ={command= H, tikz= dashed, width= 1mm}, % horizontal, dashed
    custom-line = {letter= I, tikz= dashed, width= 1mm}, % vertical, dashed
}
        
$\begin{bNiceArray}{cc I cc I c}[first-row, first-col, cell-space-top-limit=3pt, extra-margin=4pt]
        &1              &5              &2              &4              &3\\
    1   &\sfrac{1}{6}   &\sfrac{5}{6}   &0              &0              &0\\
    5   &\sfrac{1}{6}   &\sfrac{5}{6}   &0              &0              &0\\ \H % custom rule <<<<
    2   &0              &0              &\sfrac{2}{3}   &\sfrac{1}{3}   &0\\
    4   &0              &0              &\sfrac{2}{3}   &\sfrac{1}{3}   &0\\ \H % custom rule <<<<
    3   &\sfrac{1}{36}  &\sfrac{5}{36}  &\sfrac{5}{9}   &\sfrac{5}{18}  &0\\    
\end{bNiceArray}$
    
\end{document}

Used nicematrix.sty 2022/05/08 v6.8a

Update After follow-up question: bold face for the first column and the first row of the array. Use the keys

code-for-first-row and code-for-first-col

c

\documentclass[12pt,a4paper]{article}

\usepackage{xfrac} % nice fractions

\usepackage{nicematrix}
\usepackage{tikz}

\begin{document}
    
\NiceMatrixOptions
{
    custom-line ={command= H, tikz= dashed, width= 1mm}, % horizontal, dashed
    custom-line = {letter= I, tikz= dashed, width= 1mm}, % vertical dashed  
}
        
$\begin{bNiceArray}{cc I cc I c}[first-row, first-col, cell-space-top-limit=3pt, extra-margin=4pt,  code-for-first-row = $\boldmath$, code-for-first-col = $\boldmath$]% changed <<<<<<<
        &1              &5              &2              &4              &3\\
    1   &\sfrac{1}{6}   &\sfrac{5}{6}   &0              &0              &0\\
    5   &\sfrac{1}{6}   &\sfrac{5}{6}   &0              &0              &0\\ \H % custom rule <<<<
    2   &0              &0              &\sfrac{2}{3}   &\sfrac{1}{3}   &0\\
    4   &0              &0              &\sfrac{2}{3}   &\sfrac{1}{3}   &0\\ \H % custom rule <<<<
    3   &\sfrac{1}{36}  &\sfrac{5}{36}  &\sfrac{5}{9}   &\sfrac{5}{18}  &0\\    
\end{bNiceArray}$
    
\end{document}
10
  • This looks amazing but I get this error: Package nicematrix Error: The key 'custom-line' is unkno wn for the command (nicematrix) \NiceMatrixOptions. (nicematrix) If you go on, it will be ignored. (nicematrix) For a list of the principal available keys, (nicematrix) type H <return>. Oct 24, 2022 at 0:10
  • @Jeremy Weissmann You need version 6.6 or newer. I am using nicematrix.sty 2022/05/08 v6.8a Put the command \listfiles before \documentclass and look at the end of the .log file. Oct 24, 2022 at 0:23
  • Okay I have updated my version of nicematrix. (Would be nice if TeXShop did this automatically.) But now I have the same problem that the dashed lines do not appear. They do if I replace my \include header with the lines from the header file. Oct 24, 2022 at 0:26
  • @Jeremy Weissmann May be if you keep the options local ... See the update. Or use \input instead of \include. Oct 24, 2022 at 0:32
  • Doesn't draw any of the lines, not even if I replace the custom rule with | Oct 24, 2022 at 0:34

You must log in to answer this question.

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