3

I am drawing a matrix as follows:

\[\begin{tabular}{l|lllll|ll}
    & 0 & i & j & k & $\ldots$ & x & y \\ \hline
  0 & 0 & $\ldots$ & $\ldots$ & $\ldots$ & $\ldots$ & $\ldots$ & $\ldots$\\
  i & $\ldots$ & 0 & $\ldots$ & $\ldots$ & $\ldots$ & $\ldots$ & $\ldots$\\
  j & $\ldots$ & $\ldots$ & 0 & $\ldots$ & $\ldots$ & $\ldots$ & $\ldots$\\
  k & $\ldots$ & $\ldots$ & $\ldots$ & 0 & $\ldots$ & $\ldots$ & $\ldots$ \\ 
  $\vdots$ & $\ldots$ & $\ldots$ & $\ldots$ & $\ldots$ & $\ldots$ & $\ldots$ & $\ldots$\\ \hline
  x & $\ldots$ & $\ldots$ & $\ldots$ & $\ldots$ & $\ldots$ & 0 &$\ldots$\\
  y & $\ldots$ & $\ldots$ & $\ldots$ & $\ldots$ & $\ldots$ & $\ldots$ & 0
  \end{tabular}\]

And it gives:

enter image description here

The contents are fine, one problem is that I just want to keep a part of the horizontal and vertical lines which across inside the matrix. So I would like the lines to look like this image:

enter image description here Does anyone know what to do to achieve this?

5
  • 5
    Firstly, you should use the array environment instead of tabular: contents of each cell will be automatically in math mode (so you remove all the dollar signs). Secondly, for the horizontal lines, you can replace \hline by \cline[1-5] (change the numbers as needed). For the vertical line, you will have to put \multicolumn{1}{c}{$\cdots} as the contents of the cell just on the left of the line you want to remove. I hope this works, and if it does, feel free to post the resulting code. :) --- Merry Christmas! Dec 25, 2011 at 8:25
  • 3
    Ah, also, you may want to consider \ddots. Dec 25, 2011 at 8:26
  • 1
    Thanks for your comment, that does work... Merry Christmas...
    – SoftTimur
    Dec 25, 2011 at 9:28
  • 1
    @BrunoLeFloch Please tur your comment into an answer.
    – lockstep
    Dec 25, 2011 at 11:46
  • 1
    @lockstep I was hoping that SoftTimur would post the code that worked for him, and accept his own answer. A bit unconventional, but I can't easily test my code on this computer to make sure it is correct. Dec 25, 2011 at 12:33

2 Answers 2

4

Here is one solution:

\documentclass{article}

\newcommand{\novertical}[1]{\multicolumn{1}{c}{#1}}

\begin{document}

\[ \begin{array}{c|*{5}{c}|cc}
    & 0 & i & j & k & \ldots & x & y \\ \hline
  0 & 0 & \ldots & \ldots & \ldots & \ldots & \ldots & \ldots \\
  i & \ldots & 0 & \ldots & \ldots & \ldots & \ldots & \ldots \\
  j & \ldots & \ldots & 0 & \ldots & \ldots & \ldots & \ldots \\
  k & \ldots & \ldots & \ldots & 0 & \ldots & \ldots & \ldots \\[3pt]
  \smash{\vdots} & \smash{\vdots} & \smash{\vdots} & \smash{\vdots} & \smash{\vdots} & \smash{\ddots} & \smash{\vdots} & \smash{\vdots} \\ \cline{1-6}
  x & \ldots & \ldots & \ldots & \ldots & \novertical{\ldots} & 0 & \ldots \\
  y & \ldots & \ldots & \ldots & \ldots & \novertical{\ldots} & \ldots & 0
\end{array} \]

\end{document}

I incorporated @Bruno Le Floch's comments, with the following modifications:

1) I used the array environment, and got rid of all the $ signs.

2) I substituted*{5}{c} in the array declaration, just as a suggestion for future time-saving.

3) The correct command is \cline{1-6}, not \cline[1-6].

4) I used \newcommand to define a rule named \novertical, which should be used in every cell to the left of where you don't want the vertical line to appear (it takes one argument, which is the text to put in that cell).

5) I stuck with \ldots instead of \cdots, since \cdots seems to awkwardly raise the ellipses.

6) I put\vdots along the entire row before the vertical line ends, and replaced one entry there with \ddots; I think this gives the look you want.

7) I centered everything in the table; I think it looks better, but I guess that's just personal aesthetic preference.

EDIT:

8) I incorporated @egreg's comments, using \\[3pt] and \smash{\vdots} to make the row with vertical ellipses look just as tall as the others.

5
  • One follow-up question I have is: Why does the row with \vdots look taller than all the other rows? Is there a way to fix that? Dec 25, 2011 at 19:53
  • 2
    \vdots and \ddots are higher by design, to give more space that denotes more clearly omissions. Try \smash{\vdots} and \smash{\ddots}.
    – egreg
    Dec 25, 2011 at 20:21
  • When I replace all of them with \smash{\vdots}, that row of the table doesn't have enough spacing from the row above it (the two rows look smushed together)... I guess that's just a trade-off you have to face. Dec 25, 2011 at 20:25
  • 2
    If you write \\[1pt] to end the line above, you get probably a better result (adjust to suit).
    – egreg
    Dec 25, 2011 at 20:31
  • @SoftTimur: Has this answer worked for you? Mar 13, 2012 at 20:09
1

Well, lately I have been trying to do anything with TikZ which I should stop for a while I guess, but it's simplicity is too tempting to use, so here goes nothing:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{matrix}
\begin{document}
\usetikzlibrary{matrix}
\begin{tikzpicture}
\matrix (m) [matrix of nodes,nodes in empty cells]{
&  &  &  &  &  & x & y \\
&  &  &  &  &  &  & \\
&  &  &  &  &  &  & \\
&  &  &  &  &  &  & \\
&  &  &  &  &  &  &  \\ 
&  &  &  &  &  &  & \\
x&  &  &  &  &  &  &\\
y&  &  &  &  &  &  &\\
};
\draw (m-1-7.north west|- m.north) |- (m-7-1.north west -| m.west);
\draw(m.north -| m-1-2.north west) to (m.south -| m-8-2.south west);
\draw(m.west |- m-2-1.north west) to (m.east |- m-2-8.north east);
\end{tikzpicture}
\end{document}

enter image description here

I have kept the original text but if you are using math nodes, instead of matrix of nodes you can simply put matrix of math nodes. Also, the reason why I simply didn't use \draw(m-1-2) |- (m-7-4) is because when the nodes' sizes differ, I am simply getting a rough idea of where the node anchor is, say (m-1-2.north west) and then finding an orthogonal intersection of this with something that would stay(relatively) fixed, say top of the matrix m.north. And you can use these in the equations too.

Also have a look to these questions and answers:

How to put seperators

How to draw diagonal dots spanning multiple rows/columns

And maybe something you would need later:Non-vertically centered matrix of nodes

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .