0

I have a tabular environment, and what I want to do is to draw a path \emph{between} cells in that environment. Essentially, I want to show partitions of a matrix.

The table I have is as follows:

\begin{tabular}{c | c c c c c c}
& \textbf{$a_1$} & \textbf{$a_2$} & \textbf{$a_3$} & \textbf{$a_4$} & \textbf{$a_5$} & \textbf{$a_6$} \\
\hline
\textbf{$b_1$} & $a_1 b_1$ & $a_2 b_1$ & $a_3 b_1$ & $a_4 b_1$ & $a_5 b_1$ & $a_6 b_1$ \\
\textbf{$b_2$} & $a_1 b_2$ & $a_2 b_2$ & $a_3 b_2$ & $a_4 b_2$ & $a_5 b_2$ & $a_6 b_2$ \\
\textbf{$b_3$} & $a_1 b_3$ & $a_2 b_3$ & $a_3 b_3$ & $a_4 b_3$ & $a_5 b_3$ & $a_6 b_3$ \\
\textbf{$b_4$} & $a_1 b_4$ & $a_2 b_4$ & $a_3 b_4$ & $a_4 b_4$ & $a_5 b_4$ & $a_6 b_4$ \\
\textbf{$b_5$} & $a_1 b_5$ & $a_2 b_5$ & $a_3 b_5$ & $a_4 b_5$ & $a_5 b_5$ & $a_6 b_5$ \\
\textbf{$b_6$} & $a_1 b_6$ & $a_2 b_6$ & $a_3 b_6$ & $a_4 b_6$ & $a_5 b_6$ & $a_6 b_6$ \\
\end{tabular}

That displays like this: Image of a table of multiplied values

What I want to do is to draw lines that partition this table. For instance, I may want to draw a path that goes in a diagonal-ish pattern. That would have a line to the right of a4b1, under a4b1, to the right of a3b2, under a3b2, to the right of a2b3, under a2b3, to the right of a1b4, and under a1b4.

How might this be accomplished? Additionally, might there be some way to make some lines dashed, dotted, etc.? That's not critical, but it would be nice.

3

Here are some possibilities:

enter image description here

In order to position the short horizontal and vertical rules, I have used \cline and \multicolumn{1}{c|}. I have also increased the height of the rows using \setlength\extrarowheight{3pt}.

In order to achieve dashed lines, I have used the arydshln package in combination with \cdashline and \multicolumn{1}{c:}

As all contents of your table are in math mode, and not affected by \textbf, you might alos consider using an array environment instead.

\documentclass{article}
\usepackage{array}
\usepackage{arydshln}
\usepackage{bm}
  \begin{document}
\setlength\extrarowheight{3pt}

\begin{tabular}{c | c c c c c c}
& $a_1$ & $a_2$ & $a_3$ & $a_4$ & $a_5$ & $a_6$ \\
\hline
$b_1$ & $a_1 b_1$ & $a_2 b_1$ & $a_3 b_1$ & \multicolumn{1}{ c|}{$a_4 b_1$} & $a_5 b_1$ & $a_6 b_1$ \\ \cline{5-5}
$b_2$ & $a_1 b_2$ & $a_2 b_2$ & \multicolumn{1}{ c|}{$a_3 b_2$} & $a_4 b_2$ & $a_5 b_2$ & $a_6 b_2$ \\
\cline{4-4}
$b_3$ & $a_1 b_3$ & \multicolumn{1}{ c|}{$a_2 b_3$} & $a_3 b_3$ & $a_4 b_3$ & $a_5 b_3$ & $a_6 b_3$ \\
\cline{3-3}
$b_4$ & \multicolumn{1}{ c|}{$a_1 b_4$} & $a_2 b_4$ & $a_3 b_4$ & $a_4 b_4$ & $a_5 b_4$ & $a_6 b_4$ \\
\cline{2-2}
$b_5$ & $a_1 b_5$ & $a_2 b_5$ & $a_3 b_5$ & $a_4 b_5$ & $a_5 b_5$ & $a_6 b_5$ \\
$b_6$ & $a_1 b_6$ & $a_2 b_6$ & $a_3 b_6$ & $a_4 b_6$ & $a_5 b_6$ & $a_6 b_6$ \\
\end{tabular}



\setlength\dashlinegap{0.75pt}

\begin{tabular}{c | c c c c c c}
& $a_1$ & $a_2$ & $a_3$ & $a_4$ & $a_5$ & $a_6$ \\
\hline
$b_1$ & $a_1 b_1$ & $a_2 b_1$ & $a_3 b_1$ & \multicolumn{1}{ c:}{$a_4 b_1$} & $a_5 b_1$ & $a_6 b_1$ \\ \cdashline{5-5}
$b_2$ & $a_1 b_2$ & $a_2 b_2$ & \multicolumn{1}{ c:}{$a_3 b_2$} & $a_4 b_2$ & $a_5 b_2$ & $a_6 b_2$ \\
\cdashline{4-4}
$b_3$ & $a_1 b_3$ & \multicolumn{1}{ c:}{$a_2 b_3$} & $a_3 b_3$ & $a_4 b_3$ & $a_5 b_3$ & $a_6 b_3$ \\
\cdashline{3-3}
$b_4$ & \multicolumn{1}{ c:}{$a_1 b_4$} & $a_2 b_4$ & $a_3 b_4$ & $a_4 b_4$ & $a_5 b_4$ & $a_6 b_4$ \\
\cdashline{2-2}
$b_5$ & $a_1 b_5$ & $a_2 b_5$ & $a_3 b_5$ & $a_4 b_5$ & $a_5 b_5$ & $a_6 b_5$ \\
$b_6$ & $a_1 b_6$ & $a_2 b_6$ & $a_3 b_6$ & $a_4 b_6$ & $a_5 b_6$ & $a_6 b_6$ \\
\end{tabular}


\[
\begin{array}{c | c c c c c c}
&  \bm{a_1}  &  \bm{a_2}  &  \bm{a_3}  &  \bm{a_4}  &  \bm{a_5}  & \bm{a_6}  \\
\hline
\bm{b_1}  &  a_1 b_1  &  a_2 b_1  &  a_3 b_1  & \multicolumn{1}{c|}{ a_4 b_1 } &  a_5 b_1  &  a_6 b_1  \\ \cline{5-5}
 \bm{b_2}  &  a_1 b_2  &  a_2 b_2  & \multicolumn{1}{c|}{ a_3 b_2 } &  a_4 b_2  &  a_5 b_2  &  a_6 b_2  \\
\cline{4-4}
\bm{b_3} &  a_1 b_3  & \multicolumn{1}{c|}{ a_2 b_3 } &  a_3 b_3  &  a_4 b_3  &  a_5 b_3  &  a_6 b_3  \\
\cline{3-3}
 \bm{b_4} & \multicolumn{1}{c|}{ a_1 b_4 } &  a_2 b_4  &  a_3 b_4  &  a_4 b_4  &  a_5 b_4  &  a_6 b_4  \\
\cline{2-2}
\bm{ b_5 } &  a_1 b_5  &  a_2 b_5  &  a_3 b_5  &  a_4 b_5  &  a_5 b_5  &  a_6 b_5  \\
\bm{b_6} &  a_1 b_6  &  a_2 b_6  &  a_3 b_6  &  a_4 b_6  &  a_5 b_6  &  a_6 b_6  \\
\end{array}
\]


\end{document}
1

You can accomplish this using a combination of multicolumn and cline. It's cumbersome to explain. Why not using

https://tablesgenerator.com/

to create your table?

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.