1

I've been struggling with matrix underbrace, and I can't find any way through all LaTeX questions about how to use an underbrace in a matrix without the array package.

So far I got here, with these new commands, but the underbrace/overbrace is not correctly placed in the second matrix.

MWE

\documentclass[12pt]{report} \usepackage{amsmath, amssymb, etoolbox} \newcommand\aug{\fboxsep=-\fboxrule\!\!\!\fbox{\strut}\!\!\!} \newcommand\undermat[2] {\makebox[0pt][l]{$\smash{\underbrace{\phantom{\begin{matrix}#2\end{matrix}}}_{\text{$#1$}}}$}#2} \newcommand\overmat[2]{ \makebox[0pt][l]{$\smash{\overbrace{\phantom{\begin{matrix}#2\end{matrix}}}^{\text{$#1$}}}$}#2} \begin{document} $$\begin{pmatrix} 2 & 3 & 1 & \aug & 1 & 0 & 0 \\ 1 & 0 & 1 & \aug & 0 & 1 & 0 \\ \undermat{A}{ 5 & 4 & 6 } & \aug & \undermat{I}{ 0 & 0 & 0 }\\ \end{pmatrix} \xrightarrow[\rm{Jordan}]{\rm{Gauss}} \begin{pmatrix} \overmat{I}{ 1 & 0 & 0 }& \aug & \overmat{A^{-1}}{ 4/7 & 2 & -3/7 }\\ 0 & 1 & 0 & \aug & 1/7 & -1 & 1/7 \\ 0 & 0 & 1 & \aug & -4/7 & -1 & 3/7 \\ \end{pmatrix}$$ \end{document} 

enter image description here

In the second matrix, if I use \undermat{}{} it gives the same result.

7
  • 1
    why not array package (it is part of core latex, unlike say etoolbox which you are using) (I don't think it would help much here, it just seems a strange requirement in your question. The only reason array is not pre-loaded in the format is memory requirements on PCs in 1993 Commented Nov 4, 2023 at 12:28
  • 1
    \rm is not defined by default in latex, but where it is defined for compatibility with pre-1993 documents, the syntax is {\rm Jordan}] not \rm{Jordan} it did not take an argument. Commented Nov 4, 2023 at 12:30
  • I forgot, i renamed the command \textrm to \rm to make it faster. I don't like the array package because I got a lot of trouble with incompatibilites with the xltabular package and a bunch others. Commented Nov 4, 2023 at 12:32
  • 2
    that's a pretty bad choice, \rm has been known to tex syntax checkers editor highlighting etc for nearly 40 years defining a new command of the same name but different syntax will confuse everything, not just me. Commented Nov 4, 2023 at 12:35
  • 3
    Your restriction has moved from strange, to simply wrong. xltabular uses tabularx which is based on array by the same author, me:-) so you are loading array. Commented Nov 4, 2023 at 12:37

1 Answer 1

0

This might be better syntax-wise, but I don't think you have too many of these constructions in your document. Only normal sized cells are supported.

\documentclass[12pt]{report} \usepackage{amsmath} \usepackage{lipsum} \NewDocumentCommand{\undermat}{mm}{% \vphantom{\begin{matrix}#2\end{matrix}}% \smash{\,\underbrace{\begin{matrix}#2\end{matrix}}_{#1}\,}% } \NewDocumentCommand{\overmat}{mm}{% \vphantom{\begin{matrix}#2\end{matrix}}% \smash{\,\overbrace{\begin{matrix}#2\end{matrix}}^{#1}\,}% } \ExplSyntaxOn \cs_set_eq:NN \Replicate \prg_replicate:nn \ExplSyntaxOff \NewDocumentCommand{\fixunder}{m}{% \vphantom{% \underbrace{\begin{matrix}\Replicate{#1-1}{\\}\end{matrix}}_{\mathstrut}% }% } \NewDocumentCommand{\fixover}{m}{% \vphantom{% \overbrace{\begin{matrix}\Replicate{#1-1}{\\}\end{matrix}}^{\mathstrut}% }% } \begin{document} \lipsum[1][1-4] \[ \fixunder{3}\fixover{3} \left( \undermat{A}{ 2 & 3 & 1 \\ 1 & 0 & 1 \\ 5 & 4 & 6 } \;\middle|\; \undermat{I}{ 1 & 0 & 0 \\ 0 & 1 & 0 \\ 0 & 0 & 0 } \right) \xrightarrow[\textrm{Jordan}]{\textrm{Gauss}} \left( \overmat{I}{ 1 & 0 & 0 \\ 0 & 1 & 0 \\ 0 & 0 & 1 } \;\middle|\; \overmat{A^{-1}}{ 4/7 & 2 & -3/7 \\ 1/7 & -1 & 1/7 \\ -4/7 & -1 & 3/7 } \right) \] \lipsum[1][1-4] \end{document} 

Note the \fixover and \fixunder commands that take as argument the number of rows that should be considered.

Avoid $$ in LaTeX, see Why is \[ ... \] preferable to $$ ... $$?. In the sense that you should never use it inside document (there are a few cases in which $$...$$ is useful in defining commands or environments).

enter image description here

In this particular case, when the line before the display is short, you migh avoid \fixover{3} to get

enter image description here

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.