8

I want to create the matrix shown bellow in Latex. Matrix that I want

I have the horizontal curly brackets figured out, I can use undermat{}{} for that. I do not however know how to insert the vertical curly brackets around row 1 and rows 2-4, or how to insert the centered caption bellow the array.

Can someone please help me do this?

Here is my code so far with the horizontal curly brackets.

\documentclass{article}

\newcommand\undermat[2]{%
  \makebox[0pt][l]{$\smash{\underbrace{\phantom{%
    \begin{matrix}#2\end{matrix}}}_{\text{$#1$}}}$}#2}

\begin{document}

$$
\left [
\begin{array}{cccccccc}
1.2 & 1.4 & 3.2 & 4.1 & 6.3 & 7.1 & 9.4 & 2.5 \\
1.2 & 1.4 & 3.2 & 4.1 & 6.3 & 7.1 & 9.4 & 2.5 \\
1.2 & 1.4 & 3.2 & 4.1 & 6.3 & 7.1 & 9.4 & 2.5 \\
\undermat{T1}{1.2 & 1.4 & 3.2} & \undermat{T2}{1.2 & 1.4 & 3.2} & \undermat{T3}{9.4 & 2.5} \\
\end{array}
\right ]
$$

\end{document}
Blue7
  • 801

2 Answers2

8

Here's one way, using regular extensible braces:

enter image description here

\documentclass{article}

\usepackage{amsmath,lipsum}

\newcommand\undermat[2]{% http://tex.stackexchange.com/a/102468/5764
  \makebox[0pt][l]{$\smash{\underbrace{\phantom{%
    \begin{matrix}#2\end{matrix}}}_{\text{$#1$}}}$}#2}

\begin{document}

\lipsum*[1]
\[
  \begin{array}{@{} c @{}}
    \begin{array}{@{} r @{}}
      \text{Bias nodes}~\{\hspace{\nulldelimiterspace} \\
      \text{Nodes}~\left\{\begin{array}{@{}c@{}}\null\\\null\\\null\end{array}\right.
    \end{array}
    \left [
      \begin{array}{ *{8}{c} }
        1.2 & 1.4 & 3.2 & 4.1 & 6.3 & 7.1 & 9.4 & 2.5 \\
        1.2 & 1.4 & 3.2 & 4.1 & 6.3 & 7.1 & 9.4 & 2.5 \\
        1.2 & 1.4 & 3.2 & 4.1 & 6.3 & 7.1 & 9.4 & 2.5 \\
        \undermat{T1}{1.2 & 1.4 & 3.2} & \undermat{T2}{1.2 & 1.4 & 3.2} & \undermat{T3}{9.4 & 2.5} \\
      \end{array}
    \right ] \\
    \mathstrut
  \end{array}
\]
\lipsum[2]

\end{document}

Note the use of @{} to remove inter-column spacing. You may want to move the left construction closer to the matrix on the right using @{\hspace{-1ex}} (say). Your choice.

Since \undermat sets \underbraces that are \smashed, they add no vertical height to the matrices and therefore allows for the \left[...\right] construction to span only the visible matrix entries. However, this could cause the \undermats to run into content following the equation. To avoid this, we place the entire structure inside another array and add a blank line at the bottom. This allows the \smashed \undermats to have some whitespace to sink into.

Werner
  • 603,163
  • Thanks for your answer! What is the purpose of the \newcommand\undermat[2]{ bit? The code works fine without that bit. – Blue7 Mar 10 '14 at 05:21
  • @Blue7: amsmath does not supply \undermat, so I copied it from the mentioned answer. – Werner Mar 10 '14 at 05:27
  • Oh yeah, I have that bit in the header of my document. I forgot I put that there. Thanks! – Blue7 Mar 10 '14 at 05:29
  • Is there any way of making the top vertical brace bolder so that it matches the brace underneath it? bf{\left\{} doesn't work. – Blue7 Mar 10 '14 at 05:44
  • @Blue7: Try using \scalebox{1.4}[1]{$\left\{\begin{array}{@{}c@{}}\null\end{array}\right.$} instead of \{\hspace{\nulldelimiterspace}. Also make sure you have \usepackage{graphicx} in your preamble, since graphicx is the package that provides \scalebox. – Werner Mar 10 '14 at 05:54
  • This works brilliantly! It looks great when used with your other suggestion @{\hspace{-1ex}} to move the braces closer. – Blue7 Mar 10 '14 at 06:03
  • It helped me. But one request: \undermat overlaps an equation following below. Any suggestion for handling it in a nice way? – Jeon Oct 21 '17 at 13:32
  • @Jeon: I've nested the entire structure inside another array which allows you to add a blank row at the bottom. This ensures there's some whitespace the \undermats can run into. – Werner Oct 21 '17 at 20:34
0

Here is a solution with {bNiceMatrix} of nicematrix.

\documentclass{article}
\usepackage{nicematrix}

\begin{document}

[ \begin{bNiceMatrix}[first-col] \text{\itshape Bias Nodes}\hspace{4mm} & 1.2 & 1.4 & 3.2 & 4.1 & 6.3 & 7.1 & 9.4 & 2.5 \ & 1.2 & 1.4 & 3.2 & 4.1 & 6.3 & 7.1 & 9.4 & 2.5 \ \text{\itshape Nodes}\hspace{4mm} & 1.2 & 1.4 & 3.2 & 4.1 & 6.3 & 7.1 & 9.4 & 2.5 \ & 1.2 & 1.4 & 3.2 & 1.2 & 1.4 & 3.2 & 9.4 & 2.5 \ \CodeAfter \SubMatrix{{}{1-1}{1-1}{.}[xshift=1.2mm] \SubMatrix{{}{2-1}{4-1}{.}[xshift=1mm] \UnderBrace{4-1}{4-3}{T_1}[yshift=1mm,shorten] \UnderBrace{4-4}{4-5}{T_2}[yshift=1mm,shorten] \UnderBrace{4-6}{4-8}{T_3}[yshift=1mm,shorten] \end{bNiceMatrix} ]

\end{document}

You need several compilations (because nicematrix uses PGF/Tikz nodes under the hood).

Output of the above code

F. Pantigny
  • 40,250