Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I have a little problem with nested arrays.

The following examples give the correct matrix after a Latex=>PDF run but generate LaTeX errors ! missing $ inserted. <inserted text>, that I would like to get rid of.

Any idea about the problem?

First Example:

\begin{equation}
g_{22}=\left[\begin{array}{ccc}\fbox{\begin{array}{ccc}\frac{1}{E-E_1^1} & & \\ & \ddots & \\ & & \frac{1}{E-E_1^N}\end{array}} & & \\ & \ddots & \\ & &  \fbox{\begin{array}{ccc} \frac{1}{E-E_n^1} & & \\ & \ddots & \\ & & \frac{1}{E-E_n^N}\end{array}}\end{array}\right]
\end{equation}

Second example:

\begin{equation}
    H=\left[\begin{array}{cc}H_{N-n}&\begin{array}{cl}B\qquad & 0 \end{array}\\ \begin{array}{c}B^{\dag}\\ 0 \end{array} & \fbox{\begin{array}{cc}H_{n}&\quad S\\S^{\dag}&\quad\hsub\end{array}}\end{array}\right]
\end{equation}
share|improve this question
    
Welcome to TeX.sx! A tip: If you indent lines by 4 spaces or enclose words in backticks `, they'll be marked as code, as can be seen in my edit. You can also highlight the code and click the "code" button (with "{}" on it). –  doncherry Jun 30 '12 at 10:23
add comment

1 Answer

The problem goes away if the contents of the \fbox is typeset in the mathmode.

\documentclass{article}
\begin{document}
\begin{equation}
g_{22}=\left[
\begin{array}{ccc}
\fbox{$
\begin{array}{ccc}
\frac{1}{E-E_1^1} & & \\ 
& \ddots & \\ 
& & \frac{1}{E-E_1^N}
\end{array}$} & & \\ 
& \ddots & \\ 
& &  \fbox{$
           \begin{array}{ccc} 
           \frac{1}{E-E_n^1} & & \\
            & \ddots & \\ 
            & & \frac{1}{E-E_n^N}
           \end{array}$}
\end{array}\right]
\end{equation}
\end{document}

enter image description here

One can also make use of the answers given in Highlight elements in the matrix

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.