my problem is interconnected to my two previous posts (here and here) and i've tried to incorporate answers into solution but without success.
My task is this matrix multiplication with added description:
and my so far code follows:
\documentclass{article}
\usepackage{tikz,amsmath}
\begin{document}
\begin{tikzpicture}
\node[minimum height=0cm,minimum width=2cm] (m) {};
\path[shade,draw] (0,2) -- (0,5) -- (3,5) -- (3,0);
\draw (0,0) --(0,5);
\draw (3,0) --(0,2);
\draw (3,0) --(3,5);
\node (r11) at ([xshift=0.6cm,yshift=4cm]m.south) {$S_{11}$};
\node (r11) at ([xshift=2.5cm,yshift=4cm]m.south) {$S_{12}$};
\node (r11) at ([xshift=2.5cm,yshift=2.15cm]m.south) {$S_{22}$};
\node (r11) at ([xshift=0.6cm,yshift=2.15cm]m.south) {$S_{21}$};
\node (r11) at ([xshift=0.6cm,yshift=2.6cm]m.south) {$--------------$};
\node (r11) at ([xshift=0.6cm,yshift=1.5cm]m.south) {$--------------$};
\end{tikzpicture}
\[
\begin{bmatrix}
\begin{equation}
wn_{1} \\[0.3em]
wn_{2}
\end{bmatrix}
\]
\end{document}
with following output:
I am not able to add vertical line and nodes and incorporate the matrix into document (vector that follows behind the matrix is not centered). Problem with nodes and incorporation is the same as in this question.
Best Answer
Do you want something like that?
How I did it?
1- The matrix.
Tikz command
matrix
let's you define some nodes and compose them like in a tabular: columns defined with&
and new rows with\\
. Optionsdraw
andinner sep=0pt
draw an adjusted matrix border. If you commentinner sep
you will see the diference.matrix of math nodes
(you need TikZ library matrix) allow you easily declare your nodes. You don't need to use\node[options] (name) {$S_{11}$};
for every matrix node but just it's contains. This library also sets a name for every node:matrix_name-column-row
. As the matrix is namedS
, node with $S_21$ will beS-2-1
.With
nodes={nodes options}
you declare how will be all matrix nodes. In this case, their size is fixed and alsoouter sep=0pt
which makes coincide matrix border with node borders.2 - Shaded background
Once a node is declared you have some coordinates related to it (north, north west, east, ...). So, let's use them to draw the background. We need
backgrounds
library to draw anything into thebackground layer
.Syntax
(S-2-1.west) |- (S-1-2.north east)
means a vertical line which starts at(S-2-1.west)
and finishes at its intersection with an horizontal line through(S-1-2.north east)
. Then starts a horizontal line which finishes at(S-1-2.north east)
.3 - Horizontal and vertical lines
We fix where the line starts
(S-2-2.north east)
and where it will end++(180:3cm)
. This last syntax means a point which is 3cm far from the previous coordinate and following direction 180 degrees.4 - bracketed matrix
It's just a node placed 1cm to the right of coordinate
S-2-2.east
.Before to look at the complete code, and because you want to illustrate a matrix multiplication, I would suggest to look at Example: Matrix multiplication from the excellent TeXample.net.
The complete code is:
EDIT: How to find intersection between horizontal dashed line and diagonal line and draw a vertical from this point?
1- Add library
intersections
to\usetikzlibrary
in previous code.2- Add
name path = name_you_like_it
to horizontaland diagonal lines
3- Draw a vertical lined from the intersection point:
The result is:
Now I imagin you will have to change all matrix dimensions because red line is going over name of nodes. If you prefer to move the diagonal line, I suggest to read 'Tutorial: Euclid’s Amber Version of the Elements' in
TikZ
's manual.