This is actually an addition to the answer of current_user, because I placed a comment with some "tips" but after actually trying them myself they actually made placing the lines of the matrix harder.
The problem that I ran into was that I wanted to use the actual width of the column, and the actual height of the row to place the lines, but you still want to use the minimum size of the nodes for fitting nodes around them. To fix this, I added a new matrix style fixed matrix that places a fixed size node in the background of the cell, that sets the height of the row and the width of the column, and placing an additional node with the real contents on top of it (that should be smaller than the desired dimensions, otherwise it still wouldn't work). These nodes are named <matrix name>-<row num>-<column num>-o and <matrix name>-<row num>-<column num>-i where o and i denote outer and inner respectively.
With this I can easily draw the following:

With only this code:
\begin{tikzpicture}[>=latex]
\matrix [fixed matrix] (l)
{
3 & 9 & 0 & 2 & 6 & -8 \\
-1 & & -3 & 6 & & \\
2 & & & -1 & -2 & \\
& & & & -3 & 6 \\
& 3 & -1 & 3 & 1 & -2 \\
& $x^2$ & $x$ & T.I & $x$ & T.I \\
};
\draw (l-1-1-o.north east) -- (l-6-1-o.south east);
\draw[dashed] (l-1-5-o.north east) -- (l-6-5-o.south east);
\draw (l-1-1-o.south west) -- (l-1-6-o.south east);
\draw (l-4-1-o.south west) -- (l-4-6-o.south east);
\node[fit=(l-1-2-i),draw,circle,inner sep=1pt] (a) {};
\node[draw,fit=(l-1-3-i)(l-2-3-i)] (b) {};
\node[draw,fit=(l-1-4-i)(l-3-4-i)] (c) {};
\draw[->] (a.south) --++ (0,-0.6) node[right]{$ \div $} --+ (-0.4,0.4);
\draw[->] (b.south) --++ (0,-0.6) node[right]{$ \div $} --+ (-0.4,0.4);
\draw[->] (c.south) --++ (0,-0.6) node[right]{$ \div $} --+ (-0.4,0.4);
\end{tikzpicture}
Some additional functions are:
- The
fixed matrix style accepts an argument that can be used to:
- set the style for the inner nodes with
inner nodes={<style>}
- set the style of the outer nodes with
outer nodes={<style>}
- set the row height with
row height=<dimension> (default is 10mm)
- set the column width with
column width=<dimension> (default is 10mm)
Small downside, if you name the matrix before calling the fixed matrix style, you cannot refer to the individual nodes with your custom matrix name, but the default m is used as matrix name.
When changing the fixed matrix call in the previous code snippet to fixed matrix={row height=8mm,column width=8mm,inner nodes={draw=green,line width=1pt},outer nodes={dashed,draw=blue}} you can obtain the following image (just an example, definitely not a proposed improvement):

Complete code (many many thanks to current_user for his start on this):
\documentclass[border=2mm,tikz]{standalone}
\usetikzlibrary{fit}
\tikzset{
fixed matrix/.cd,
row height/.initial=10mm,
column width/.initial=10mm,
name/.initial=m,
inner node style/.style={},
outer node style/.style={},
inner nodes/.code={\tikzset{fixed matrix/inner node style/.style={#1}}},
outer nodes/.code={\tikzset{fixed matrix/outer node style/.style={#1}}},
}
\tikzset{
fixed matrix/.style={
inner sep=0pt,
nodes={inner sep=0.333em},
name/.forward to=/tikz/fixed matrix/name,
execute at begin cell={
\node[
inner sep=0pt,
minimum width=\pgfkeysvalueof{/tikz/fixed matrix/column width},
minimum height=\pgfkeysvalueof{/tikz/fixed matrix/row height},
fixed matrix/outer node style,
] (\pgfkeysvalueof{/tikz/fixed matrix/name}-\the\pgfmatrixcurrentrow-\the\pgfmatrixcurrentcolumn-o){};
\node[fixed matrix/inner node style] (\pgfkeysvalueof{/tikz/fixed matrix/name}-\the\pgfmatrixcurrentrow-\the\pgfmatrixcurrentcolumn-i) \bgroup},
execute at end cell={\egroup;},
execute at empty cell={
\node[
inner sep=0pt,
minimum width=\pgfkeysvalueof{/tikz/fixed matrix/column width},
minimum height=\pgfkeysvalueof{/tikz/fixed matrix/row height},
fixed matrix/outer node style,
] (\pgfkeysvalueof{/tikz/fixed matrix/name}-\the\pgfmatrixcurrentrow-\the\pgfmatrixcurrentcolumn-o){};},
},
fixed matrix/.append code=\tikzset{fixed matrix/.cd,#1},
}
\begin{document}
\begin{tikzpicture}[>=latex]
\matrix [fixed matrix={row height=8mm,column width=8mm,inner nodes={draw=green,line width=1pt},outer nodes={dashed,draw=blue}}] (l)
{
3 & 9 & 0 & 2 & 6 & -8 \\
-1 & & -3 & 6 & & \\
2 & & & -1 & -2 & \\
& & & & -3 & 6 \\
& 3 & -1 & 3 & 1 & -2 \\
& $x^2$ & $x$ & T.I & $x$ & T.I \\
};
\draw (l-1-1-o.north east) -- (l-6-1-o.south east);
\draw[dashed] (l-1-5-o.north east) -- (l-6-5-o.south east);
\draw (l-1-1-o.south west) -- (l-1-6-o.south east);
\draw (l-4-1-o.south west) -- (l-4-6-o.south east);
\node[fit=(l-1-2-i),draw,circle,inner sep=1pt] (a) {};
\node[draw,fit=(l-1-3-i)(l-2-3-i)] (b) {};
\node[draw,fit=(l-1-4-i)(l-3-4-i)] (c) {};
\draw[->] (a.south) --++ (0,-0.6) node[right]{$ \div $} --+ (-0.4,0.4);
\draw[->] (b.south) --++ (0,-0.6) node[right]{$ \div $} --+ (-0.4,0.4);
\draw[->] (c.south) --++ (0,-0.6) node[right]{$ \div $} --+ (-0.4,0.4);
\end{tikzpicture}
\end{document}
tikzto me. – Derek Aug 28 '18 at 01:13