2

I want to type the matrix

enter image description here

So I try to make this code

\documentclass{article}
\usepackage{nicematrix}
\begin{document}
    \begin{align*}
        \begin{bNiceMatrix}
            1&0&0&\Ldots&&0\\
            h_1&2(h_1+h_2)&h_2&&&\Vdots\\
            0&h_2&2(h_2+h_3)&h_3&\Ddots&\\
            \Vdots&\Ddots&\Ddots&\Ddots&\Ddots&0\\
            &&&h_{n-2}&2(h_{n-2}+h_{n-1})&h_{n-1}\\
            0&\Cdots&&0&0&1\\
        \end{bNiceMatrix}
    \end{align*}
\end{document}

Now I get this result:

enter image description here

I don't want the \Ddots intersect the element of matrix and I want \Ddots under $2(h_2+h_3)$ is longer (as the first picture). How to make it?

1
  • 1
    (I'm the author of nicematrix). By default, nicematrix draws the diagonal lines parallel to the first one. It's possible to change the first line drawn. It's also possible to completely deactivate parallelization. However, in your case, the best way is certainly the answer of Simon Dispa (with \line in the \CodeAfter). Commented Apr 25, 2021 at 15:08

1 Answer 1

2

You will get a better result by drawing the diagonal dotted lines with the command \line in the \CodeAfter, including in the case of the second 0 of the last row.

enter image description here

\documentclass{article}

\usepackage{nicematrix}

\begin{document}
    
    \begin{align*}
        \begin{bNiceMatrix}
            1       &0          &0          &\Ldots     &                   &0      \\
            h_1     &2(h_1+h_2) &h_2        &           &                   &\Vdots \\
            0       &h_2        &2(h_2+h_3) &h_3        &\Ddots             &       \\
            \Vdots  &           &           &           &                   &0      \\  % changed <<<<<<<<<
                    &           &           &h_{n-2}    &2(h_{n-2}+h_{n-1}) &h_{n-1}\\
            0       &\Cdots     &           &0          &0                  &1      \\
            \CodeAfter  % added <<<<<<<<<<<<
                \line{3-1}{6-4}
                \line{3-2}{5-4}  
                \line{3-3}{5-5}
                \line{3-4}{5-6}
        \end{bNiceMatrix}
    \end{align*}

\end{document}

You must log in to answer this question.

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