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


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. – Andrew Stacey 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

Here is how I would do it:




% 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.


% Calculate length of rules.
\if \mylenA < \mylenB

% Matrix construction.
    \begin{array}{@{} c | c @{}}
      & \begin{array}{c}
         \hspace{\WhiteSpace} #3 \hspace{\WhiteSpace}
      & \raisebox{-0.3ex}{$#4$}

% 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})}


% Widths of expressions in matrix entries.

  % Width of whitespace on each side of horizontal lines.
  % Math expression.
  H_{f,g} \binom{\vect{a}}{\lambda}
  = \Matrix{\entryA}{\entryB}{\entryC}{\entryD}



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.


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.


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


enter image description here


Something like that?

\usepackage{mathtools, array}



    & & & \vrule \\
    \multicolumn{3}{c|}{\hess_{f, g}(f)(\mathbf a)} & \nabla g(\mathbf a)\\
      & & & \vrule \\[-2.6ex] & & & \\
    \longline & Dg(\mathbf a) &\longline & 0
  \end{bmatrix} \]%


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

How to do this using normal TeX tools:

\def\lrule{\leaders\hrule height3pt depth-2.6pt\hskip2em \relax}
\def\Hess{\mathop{\rm Hess}\nolimits}
  H_{f,g} {\vec a \choose \lambda} =
     \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
        \lrule\ Dg(\vec a)\ \lrule & 0 \cr
  • 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.