5

I want to make a matrix that incorporates both multirow and multicolumn. However the code doesn't work. Sorry if the question is stupid, I am playing with matrices the whole day and probably I am tired and missing something obvious.

\usepackage{arydshln}

\usepackage{array}

\usepackage{amsmath}

\usepackage{multirow} \begin{document}

\begin{align*}

& \hspace{0.3cm}\overbrace{\hphantom{\begin{array}{ccc}
a&b&c \end{array}}}\\    
&\left[
\begin{array}{ccc:ccc:ccc}

a&a&a&b&b&b&c&c&c\\

\multicolumn{3}{c}{0}&\multicolumn{3}{c}{0}&\multicolumn{3}{c}{\multirow{2}{c}{0}}\\    
1&2&3&4&5&6&&&\\

\end{array} \right]

\end{align*} 

\end{document}
David Carlisle
  • 757,742
lhj7362
  • 417
  • 1
  • 4
  • 8
  • Welcome to tex.sx! A tip: If you indent lines by 4 spaces, then they are marked as a code sample. You can also highlight the code and click the "code" button (with "101010" on it). – lockstep Mar 08 '11 at 18:52

2 Answers2

4
  • Load arydshln after array instead of before. According to the manual, arydshln has to be loaded after array, longtable, colortab, and colortbl, respectively.

  • Correct the second argument to multirow. It should be a width or a * meaning the natural width.

With these corrections, the code works:

\documentclass{article}
\usepackage{array}
\usepackage{arydshln}
\usepackage{amsmath}
\usepackage{multirow}
\begin{document}
\begin{align*}
& \hspace{0.3cm}\overbrace{\hphantom{\begin{array}{ccc}
a&b&c \end{array}}}\\    &\left[
\begin{array}{ccc:ccc:ccc}
a&a&a&b&b&b&c&c&c\\
\multicolumn{3}{c}{0}&\multicolumn{3}{c}{0}&\multicolumn{3}{c}{\multirow{2}{*}{0}}\\    1&2&3&4&5&6&&&\\
\end{array} \right]
\end{align*} 
\end{document}

Output:

multirow multicolumn example

David Carlisle
  • 757,742
Stefan Kottwitz
  • 231,401
  • I found that out myself =) However thanks for your answer, I didn't think I am getting any. Also what about $$'s in multirow argument?(look my answer?) – lhj7362 Mar 08 '11 at 19:55
  • 1
    @lhj7362: \multirow produces a box, inside it's not in math mode any more. You have to start math mode again inside this box. It's a similar situation with \mbox or \parbox. – Stefan Kottwitz Mar 08 '11 at 21:38
1

So, getting no responces, I solved the problem myself. First, if you use just \multicolumn, you should NOT take 3rd argument into $$'s. However if you put \multirow inside a \multicolumn you SHOULD take it into $$'s.

Second, the second argument of both \multicolumn and \multirow defines placing of the content within that area, but placing c as the \multirow argument makes the code incompilable for some reason. That error is also hard to spot. The below code works for me (note the added $$'s).

\begin{align*}
&\left[
\begin{array}{ccc:ccc:ccc}
a&a&a&b&b&b&c&c&c\\
\multicolumn{3}{c}{0}&\multicolumn{3}{c}{0}&\multicolumn{3}{c}{\multirow{2}{*}{$\phi$}}\\
1&2&3&4&5&6&&&\\
\end{array} \right]
\end{align*} 
\end{document}
David Carlisle
  • 757,742
lhj7362
  • 417
  • 1
  • 4
  • 8