2

I was wondering how I can so something similar to the answer given here

How to shade or highlight the upper or lower triangular part in a matrix?

by Bibi but for the lower triangular part. Can someone also tell me where I can find more information about the \node command and what (m-x-y) (e.g. (m-1-1) means.

  • 3
    It would be great if you could show us what you have tried. Posting a minimal working example that indicates what you are trying to do makes it easier for people to understand what you want. It also makes it easier for people to help you, since they have some code to start from, and hence much more likely that some one will try to help you. With the question you linked to, (m-1-1) refers to the matrix entry in row 1, column 1 etc. Armed with this information you should be able to fill in the rest of the details yourself! :) –  Jun 23 '17 at 21:51
  • m-x-y means matrix m, column n. x, row n. y. Hence, m-1-1 is the node at the first column and first row of matrix m. – CarLaTeX Jun 23 '17 at 23:02
  • Welcome! Please make your question here self-contained. It shouldn't rely on the other question staying the same, though you should obviously provide the link, as you have, both to attribute the code and provide background for people who want it. You can find information about \node etc. in the TikZ manual. Nodes, at least, are certainly covered in the introductory tutorials in the first part of the document. – cfr Jun 23 '17 at 23:22

2 Answers2

5

Exactly the same way as in the linked answer but with different coordinates.

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{backgrounds,matrix,fit}
\begin{document}
\begin{tikzpicture}
  \matrix[matrix of math nodes,left delimiter = (,right delimiter = ),row sep=10pt,column sep = 10pt] (m)
  {
    1  &3 &-8\\
    2  &0 &1\\
    -7 &9 &1\\
  };
  \begin{pgfonlayer}{background}
    \node[inner sep=3pt,fit=(m-1-1)]          (1)   {};
    \node[inner sep=3pt,fit=(m-2-1) (m-3-2)]  (2)   {};
    \node[inner sep=3pt,fit=(m-3-3)]          (3)   {};
    \draw[rounded corners,dotted,fill=green!50!white,inner sep=3pt,fill opacity=0.1]
    (1.north west) |- (3.south east) |- (2.east) |- (2.north) |- (1.north) -- cycle;
  \end{pgfonlayer}
\end{tikzpicture}
\end{document}

enter image description here

Henri Menke
  • 109,596
2

Let first illustrate *CarLaTeX comment! If a matrix has declared nodes (ordinary or math) and has a name, than each node in matrix has name determined by:

<name of matrix>-<row index>-<column index>

Fro example, matrix 3 x 3 with ordinary nodes, which contains names of nodes, we can write as:

\documentclass[tikz, margin=3mm]{standalone}
\usetikzlibrary{matrix}

\begin{document}
    \begin{tikzpicture}
\matrix (m) [matrix of nodes,
             row sep=3pt, column sep = 3pt,
             font=\footnotesize
             ]
{
m-1-1   &   m-1-2   &   m-1-3\\
m-2-1   &   m-2-2   &   m-2-3\\
m-3-1   &   m-3-2   &   m-3-3\\
};
\draw[red] (m-2-1.center) -- (m-3-2.center) -- (m-1-3.center);
    \end{tikzpicture}
\end{document}

where red line serve as "proof" for nodes' names.

enter image description here

Knowing that, your problem can be solved also on the following way:

\documentclass[tikz, margin=3mm]{standalone}
\usetikzlibrary{backgrounds, matrix}

\begin{document}
    \begin{tikzpicture}
\matrix (m) [matrix of math nodes,
             left delimiter = (,
             right delimiter = ),
             nodes={minimum size=2em}
             ]
{
1   &   3   &   -8\\
2   &   0   &   1 \\
-7  &   9   &   1 \\
};
    \begin{pgfonlayer}{background}
\draw[rounded corners, dotted, fill=green!10!white]
    (m-1-1.north) -| (m-1-1.south east) -| (m-2-2.south east)
                  -| (m-3-3.south east) -| (m-1-1.west)
                  |- (m-1-1.north);
    \end{pgfonlayer}
    \end{tikzpicture}
\end{document}

![enter image description here

Zarko
  • 296,517