10

Good evening,

I'm trying to achieve following picture in latex, but i can't do it. Can someone help me? enter image description here

This is what I have so far:

\documentclass[a4paper,12pt]{scrartcl}

\usepackage{booktabs}
\usepackage[utf8] {inputenc}
\usepackage[ngerman]{babel}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{amsfonts}
\usepackage[T1]{fontenc}

\begin{document}

\begin{center}
      $\left(\begin{array}{rrrr}
             2&2&-1&3  \\
            \cmidrule{2-4}
             0&1&3&4  \\
             0&1&3&4  \\
             0&3&9&6  \\
             0&1&3&-2  
    \end{array}\right)$
\end{center}

\end{document}
12

You're missing the vertical line | in the column specification and a \multicolumn{1}{r} for the element in the top left corner:

enter image description here

\documentclass{article}

\begin{document}

\[
  \left(
    \begin{array}{ r | *{3}{r} }
      \multicolumn{1}{r}{2} & 2 & -1 &  3 \\
      \cline{2-4}
      0 & 1 &  3 &  4 \\
      0 & 1 &  3 &  4 \\
      0 & 3 &  9 &  6 \\
      0 & 1 &  3 & -2  
    \end{array}
  \right)
\]

\end{document}

For a more evenly distributed spacing around the last three columns, consider using \phantom{-}2 in the first row:

enter image description here

\documentclass{article}

\begin{document}

\[
  \left(
    \begin{array}{ r | *{3}{r} }
      \multicolumn{1}{r}{2} & \phantom{-}2 & -1 &  3 \\
      \cline{2-4}
      0 & 1 &  3 &  4 \\
      0 & 1 &  3 &  4 \\
      0 & 3 &  9 &  6 \\
      0 & 1 &  3 & -2  
    \end{array}
  \right)
\]

\end{document}
1
10

With nicematrix. The environments of nicematrix create PGF/Tikz nodes under the rows, columns and cells and the array and it's possible to use them to draw whatever you want with Tikz.

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

\begin{document}

\[
\begin{pNiceMatrix}[r,right-margin,columns-width=auto]
  2 & 2 & -1 &  3 \\
  0 & 1 &  3 &  4 \\
  0 & 1 &  3 &  4 \\
  0 & 3 &  9 &  6 \\
  0 & 1 &  3 & -2  
\CodeAfter
\tikz \draw ([xshift=4pt]row-6-|col-2) |- (row-2-|col-5) ;
\end{pNiceMatrix}
\]

\end{document}

Output of the above code

5
  • Thank you very much! – Francesco Tallarico Dec 30 '20 at 21:14
  • Is it also possible to draw dotted lines ? – Francesco Tallarico Dec 30 '20 at 21:18
  • 1
    @Francesco: Yes. Put \draw [dotted] instead of \draw. – F. Pantigny Dec 30 '20 at 21:29
  • To my eyes the horizontal line is a little too low. – Anush Dec 30 '20 at 21:58
  • 1
    @Anush That's why this approach is more powerful. You only need e.g. \tikz \draw ([xshift=4pt]row-6-|col-2) |- ([yshift=2pt]row-2-|col-5) ;, or whatever yshift you like. And have access to many other things such as decorated lines. – user232027 Jan 1 at 1:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.