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.

  • 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 – David Carlisle Nov 04 '23 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. – David Carlisle Nov 04 '23 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. – Agente 156 Nov 04 '23 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. – David Carlisle Nov 04 '23 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. – David Carlisle Nov 04 '23 at 12:37
  • Ok, sorry, i didn't test enough the array package and I was skeptical about it and the incompatibilities, I'm probably going to delete this question, but now that you are here, the creator of xltabular, can I ask you how to move the title of a section to a new page if an xltabular environment inmediatly breaks page. I mean that there is some cases were the title of the section is in the last line of the page and the xltabular starts in a new page and it looks weird. Thank you for you LaTeX colaborations – Agente 156 Nov 04 '23 at 12:52
  • it shouldn't happen, but if it does, simplest is probably to just put \clearpage before the \section – David Carlisle Nov 04 '23 at 13:21

1 Answers1

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

egreg
  • 1,121,712