12

I am supposed to use the following matrix in a math problem:

wanted

But based on my experience with LaTeX's tables and matrices, I know this is beyond me.

Can anyone tell me how to make the following matrix? Any help would be great. I assume I need to use bmatrix but after that I am stumped.

  • 3
    I totally misread the title for this question. I was going to suggest that taffeta might be a better choice. – Loop Space May 10 '15 at 0:31
  • When and how did you escape from Azkaban? :-) – Mico May 10 '15 at 6:21
  • 1
    @Mico Ernie and a group of hired wizard hoodlums broke me out. The plan involved felix felicis and a lot of butter beer. Details on the date are a bit hush hush. Azkaban covered it up to avoid embarrassment. – Stan Shunpike May 10 '15 at 7:05
  • "I am supposed to ... " Who is supposing? Is this homework? – Benjamin McKay May 10 '15 at 11:12
14

Here is how I would do it:

\documentclass{article}

\usepackage{mathtools}
\usepackage{bm}

\DeclareMathOperator{\Hess}{Hess}
\newcommand*\vect[1]{\mathbf{#1}}

% http://tex.stackexchange.com/a/59955/15874
% The following piece of code measures the length of math expressions
% in order to get the length of the two horizontal rules (based on
% the chosen width of the whitespaces) in the matrix.
\makeatletter
\newcommand*\settowidthofalign[2]{%
  \setbox\z@=\vbox{
    \begin{align*}
    #2
    \ifmeasuring@\else\global\let\got@maxcolwd\maxcolumn@widths\fi
    \end{align*}
  }%
  \begingroup
  \def\or{+}\edef\x{\endgroup#1=\dimexpr\got@maxcolwd\relax}\x}
\makeatother

\newlength{\mylenA}
\newlength{\mylenB}

% Calculate length of rules.
\if \mylenA < \mylenB
  \newcommand*\ruleLength{\the\dimexpr(\mylenA-\mylenB-4*(\WhiteSpace))/2\relax}
 \else
  \newcommand*\ruleLength{\the\dimexpr(\mylenB-\mylenA-4*(\WhiteSpace))/2\relax}
\fi

% Matrix construction.
\newcommand*\Matrix[4]{%
  \left[
    \begin{array}{@{} c | c @{}}
      #1
      & \begin{array}{c}
          \vert\\
          #2\\
          \vline
          \vspace{0.5ex}
         \end{array}\\
      \hline
      \vspace{0.5ex}
      \raisebox{-0.3ex}{%
        $\rule[0.5ex]{\ruleLength}{0.4pt}
         \hspace{\WhiteSpace} #3 \hspace{\WhiteSpace}
         \rule[0.5ex]{\ruleLength}{0.4pt}$%
      }
      & \raisebox{-0.3ex}{$#4$}
    \end{array}
  \right]%
}

% Matrix entries.
\newcommand*\entryA{\Hess(f)(\vect{a}) - \lambda\Hess(g)(\vect{a})}
\newcommand*\entryB{\bm{\nabla} g(\vect{a})}
\newcommand*\entryC{D g(\vect{a})}
\newcommand*\entryD{0}

\begin{document}

% Widths of expressions in matrix entries.
\settowidthofalign{\mylenA}{\entryA}
\settowidthofalign{\mylenB}{\entryB}

\begin{equation*}
  % Width of whitespace on each side of horizontal lines.
  \def\WhiteSpace{12pt}
  % Math expression.
  H_{f,g} \binom{\vect{a}}{\lambda}
  = \Matrix{\entryA}{\entryB}{\entryC}{\entryD}
\end{equation*}

\end{document}

output

This might be overkill in this particular case but you now have a working construction that can be re-used for other matrices. All you have to do is

  • define the entries of the new matrix (e.g., \entryE),
  • define the new lengths to be used (using \newlength),
  • let TeX calculate the widths of the math expressions (using \settowidthofalign),
  • typeset the whole shebang (using \Matrix).

Note: I wouldn't make the \nabla bold; I think it disturbes the reading more than it helps.

12

Here is an approach with an array and some \rule commands for the extra lines inside of cells. Note that the array actually consists of four rows.

Code

\documentclass[varwidth]{standalone}
\usepackage{amsmath,bm}
\DeclareMathOperator\Hess{Hess}
\begin{document}
\begin{equation*}
\renewcommand*\a{\mathbf{a}}
\newcommand*\vl{\rule[-.3em]{.4pt}{1em}}
\newcommand*\hl{\rule[.5ex]{2em}{.4pt}}
%
H_{f,g}\binom{\a}{\lambda} = \left[\begin{array}{c|c}
                                  & \vl          \\
 \Hess(f)(\a)-\lambda\Hess(g)(\a) & \nabla g(\a) \\
                                  & \vl          \\ \hline
 \hl\quad Dg(\a) \quad\hl         & 0
\end{array}\right]
\end{equation*}
\end{document}

Output

enter image description here

7

Something like that?

\documentclass{article}
\usepackage{amssymb}
\usepackage{mathtools, array}
\DeclareMathOperator{\hess}{Hess}

\def\longline{\relbar\mkern-6mu\relbar}

\begin{document}

\[\setlength\extrarowheight{1pt}
  \begin{bmatrix}
    \begin{array}{c@{\,}c@{\,}c|c}
    & & & \vrule \\
    \multicolumn{3}{c|}{\hess_{f, g}(f)(\mathbf a)} & \nabla g(\mathbf a)\\
      & & & \vrule \\[-2.6ex] & & & \\
    \hline
    \longline & Dg(\mathbf a) &\longline & 0
    \end{array}
  \end{bmatrix} \]%

\end{document} 

enter image description here

  • 3
    --> \nabla. – Svend Tveskæg May 10 '15 at 3:40
  • @Svend Tvskæg: Thanks for pointing it. WinEdt struck again! Corrected now. – Bernard May 10 '15 at 10:38
6

How to do this using normal TeX tools:

\def\vec#1{{\bf#1}}
\def\lrule{\leaders\hrule height3pt depth-2.6pt\hskip2em \relax}
\def\Hess{\mathop{\rm Hess}\nolimits}
$$
  H_{f,g} {\vec a \choose \lambda} =
  \left[
  \vcenter{\offinterlineskip
     \halign{\hfil$#$\ \hfil\vrule height10pt depth5pt&\hfil\ $#$\hfil\cr
        & | \cr
        \Hess(f)(\vec a) - \lambda \Hess(g)(\vec a) & \nabla g(\vec a) \cr
        & | \cr
        \noalign{\hrule}
        \lrule\ Dg(\vec a)\ \lrule & 0 \cr
  }}
  \right]
$$
  • Don't forget \bye -- just to make the code fully self-contained. :-) – Mico May 10 '15 at 6:24
  • @Mico I didn't type \bye because the code is usable in LaTeX too. (No in ConTeXt because ConTeXt changes the category of &). – wipet May 10 '15 at 6:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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