2

How can I avoid the bad box

\documentclass[12pt]{article} 

\usepackage{amsmath}
\usepackage{bm} 
\usepackage{bigdelim}
\usepackage{multirow}

\begin{document}
\begin{eqnarray*}
  \bm{y} =
  \begin{matrix}
  \ldelim[{2}{0.1cm}& \bm{y}_{1}\    \rdelim]{2}{0.1cm}& n_1\\
                    & \bm{y}_{2}\  & n_2\\
  \end{matrix}
  ,\bm{\mu} =
  \begin{matrix}
  \ldelim[{2}{0.1cm}& \bm{\mu}_{1}\ \rdelim]{2}{0.1cm}&n_1\\
                    & \bm{\mu}_{2}\  & n_2\\
  \end{matrix}
\end{eqnarray*}
\begin{eqnarray*}
\Sigma =
  \begin{matrix}
\ldelim[{2}{0.1cm}& \Sigma_{11} & \Sigma_{12}\ \rdelim]{2}{0.1cm}&n_1\\
              & \Sigma_{21} & \Sigma_{22}\ & n_2\\
              &n_1 & n_2 &\\
\end{matrix}
\end{eqnarray*}
\end{document}

%---------------------------------------------------------------

Overfull \hbox (4.68791pt too wide) in paragraph at lines 12--12
[]|$[]$|  

Overfull \hbox (4.68791pt too wide) in paragraph at lines 17--17
[]|$[]$|  

Overfull \hbox (4.68791pt too wide) in paragraph at lines 17--17
[]|$[]$|  

Or I can also use align*

\begin{align*}
  \bm{y} =
  \begin{matrix}
  \ldelim[{2}{0.1cm}& \bm{y}_{1}\ \rdelim]{2}{0.1cm}&n_1\\
                    & \bm{y}_{2}\  & n_2\\
  \end{matrix}
  \quad, \bm{\mu} =
  \begin{matrix}
  \ldelim[{2}{0.1cm}& \bm{\mu}_{1}\ \rdelim]{2}{0.1cm}&n_1\\
                    & \bm{\mu}_{2}\  & n_2\\
  \end{matrix}
\end{align*}
\begin{align*}
\Sigma =
  \begin{matrix}
\ldelim[{2}{0.1cm}& \Sigma_{11} & \Sigma_{12}\ \rdelim]{2}{0.1cm}&n_1\\
              & \Sigma_{21} & \Sigma_{22}\ & n_2\\
              &n_1 & n_2 &\\
\end{matrix}
\end{align*}

However, the problems will be doubled.

Overfull \hbox (6.11073pt too wide) in paragraph at lines 21--21
[]|$[]$|  

Overfull \hbox (6.11073pt too wide) in paragraph at lines 21--21
[]|$[]$|  

Overfull \hbox (4.68791pt too wide) in paragraph at lines 21--21
[]|$[]$|  

Overfull \hbox (4.68791pt too wide) in paragraph at lines 21--21
[]|$[]$|  

Overfull \hbox (6.11073pt too wide) in paragraph at lines 21--21
[]|$[]$|  

Overfull \hbox (6.11073pt too wide) in paragraph at lines 21--21
[]|$[]$|  

Overfull \hbox (4.68791pt too wide) in paragraph at lines 21--21
[]|$[]$|  

Overfull \hbox (4.68791pt too wide) in paragraph at lines 21--21
[]|$[]$|  

Overfull \hbox (4.68791pt too wide) in paragraph at lines 29--29
[]|$[]$|  

Overfull \hbox (4.68791pt too wide) in paragraph at lines 29--29
[]|$[]$|  

Overfull \hbox (4.68791pt too wide) in paragraph at lines 29--29
[]|$[]$|  

Overfull \hbox (4.68791pt too wide) in paragraph at lines 29--29
[]|$[]$|  
Magic-A
  • 23

2 Answers2

3

First of all, never use eqnarray: See eqnarray vs align, but don't use align either if the display is single line.

However, the overfull boxes are caused by \ldelim and \rdelim, not by eqnarray.

You are using the wrong tools, in my opinion.

\documentclass[12pt]{article} 

\usepackage{amsmath}
\usepackage{bm} 

\begin{document}

\begin{equation*}
\bm{y} =
\begin{bmatrix}
\bm{y}_{1}\\ \bm{y}_{2}
\end{bmatrix}
\;
\begin{matrix}
n_1\\ n_2\\
\end{matrix}
,\qquad
\bm{\mu} =
\begin{bmatrix}
\bm{\mu}_{1} \\
\bm{\mu}_{2}
\end{bmatrix}
\;
\begin{matrix}
n_1\\
n_2
\end{matrix}
\end{equation*}

\end{document}

enter image description here

A more complex macro, that takes care of bigger entries in the matrix.

\documentclass[12pt]{article} 

\usepackage{amsmath}
\usepackage{bm}
\usepackage{xparse}

\ExplSyntaxOn
\NewDocumentCommand{\blockcolumn}{m}
 {
  \seq_clear:N \l_magica_blockcolumn_index_seq
  \seq_set_split:Nnn \l_magica_blockcolumn_rows_seq { \\ } { #1 }
  \seq_map_inline:Nn \l_magica_blockcolumn_rows_seq
   {
    \seq_set_split:Nnn \l__magica_blockcolumn_temp_seq { & } { ##1 }
    \seq_put_right:Nx \l_magica_blockcolumn_index_seq
     {
      \seq_item:Nn \l__magica_blockcolumn_temp_seq { 2 }
     }
   }
  \hbox_set:Nn \l_magica_blockcolumn_index_box
   {
    $\begin{matrix}
    \seq_use:Nn \l_magica_blockcolumn_index_seq { \\ }
    \end{matrix}$
   }
  \begin{bmatrix}
  \seq_use:Nn \l_magica_blockcolumn_rows_seq
   { \hspace{\dim_eval:n { -\box_wd:N \l_magica_blockcolumn_index_box-2\arraycolsep}} \\ }
  \hspace{\dim_eval:n { -\box_wd:N \l_magica_blockcolumn_index_box-2\arraycolsep}}
  \end{bmatrix}
 }
\seq_new:N \l_magica_blockcolumn_rows_seq
\seq_new:N \l_magica_blockcolumn_index_seq
\seq_new:N \l__magica_blockcolumn_temp_seq
\box_new:N \l_magica_blockcolumn_index_box
\ExplSyntaxOff

\begin{document}

\begin{equation*}
\bm{y}=
\blockcolumn{
\bm{y}_{1} & n_1\\
\bm{y}_{2} & n_2
}
\\
,\qquad
\bm{\mu} =
\blockcolumn{
\sum\limits_{i=1}^k \bm{\mu}_{1i} & n_1\\
\bm{\mu}_{2} & n_2
}
\end{equation*}

\end{document}

enter image description here

egreg
  • 1,121,712
  • Thank you for you answer. If just doing a vector, your result is perfect. However, the utimate aim of this is to do the third formula (I updated the question). I used align* in the previous, but there are also badbox, so I try to use this. – Magic-A Jan 17 '17 at 18:37
2

You are trying to produce some form of bordered matrix and so could use the blkarray package, cf. https://tex.stackexchange.com/a/346979/15925 . So for the final example you would write something like

\begin{blockarray}{ccc}
  \begin{block}{[cc]c}
    \Sigma_{11} & \Sigma_{12} &n_1\\
    \Sigma_{21} & \Sigma_{22} & n_2\\
  \end{block}
  n_1 & n_2 &
\end{blockarray} 

which produces an alignment with three columns all centered, specified by the initial {ccc} option, but has a submatrix with alignment {[cc]c}, meaning the first two columns are enclosed in square brackets, large enough to enclose the rows of that block.

Unfortunately, you then run in to some vertical alignment problems with the rest of the material. One way to fix these is via adjustbox:

Sample output

\documentclass[12pt]{article}

\usepackage{amsmath}
\usepackage{blkarray,adjustbox}
\usepackage{bm}

\begin{document}
\begin{equation*}
  \bm{y} =
  \begin{adjustbox}{raise=-1ex} $\displaystyle
    \begin{blockarray}{[c]c}
      \bm{y}_{1} & n_1\\
      \bm{y}_{2} & n_2
    \end{blockarray} $
  \end{adjustbox}
  ,\quad
  \bm{\mu} =
  \begin{adjustbox}{raise=-1ex} $\displaystyle
    \begin{blockarray}{[c]c}
      \bm{\mu}_{1}&n_1\\
      \bm{\mu}_{2}& n_2
    \end{blockarray} $
  \end{adjustbox}
\end{equation*}

\begin{equation*}
  \Sigma =
  \begin{adjustbox}{raise=-2.5ex} $\displaystyle
    \begin{blockarray}{ccc}
      \begin{block}{[cc]c}
        \Sigma_{11} & \Sigma_{12} &n_1\\
        \Sigma_{21} & \Sigma_{22} & n_2\\
      \end{block}
      n_1 & n_2 &
    \end{blockarray} $
  \end{adjustbox}
\end{equation*}
\end{document}
Andrew Swann
  • 95,762