12

Is it possible to give an equation number to each row of a matrix equation?

enter image description here

How could I have equation labels in the vein of subequation numbers, one for each row of the matrix equation? Here, I'd like equation numbers such as, e.g., (3.1a), (3.1b), (3.1c) (I don't mean row/column labels as in a bordered matrix).

Thanks!

Dominique
  • 1,369

4 Answers4

13

Hmm! not really supported LaTeX syntax but

output

\documentclass{article}

\usepackage{amsmath}

\newsavebox\labelbox

\begin{document}

\savebox\labelbox{$\begin{matrix}
\refstepcounter{equation}(\theequation)\label{aa}\\
\refstepcounter{equation}(\theequation)\label{bb}\\
\refstepcounter{equation}(\theequation)\label{cc}
\end{matrix}$}

\[
  \begin{bmatrix}
    H            & J^T       & -Z^{\frac12} \\
    J            & -\delta I &              \\
    -Z^{\frac12} &           & -X
  \end{bmatrix}
  \begin{bmatrix}
    r \\ s \\ t
  \end{bmatrix}
  =
  \lambda
  \begin{bmatrix}
    H &   &  \\
      & U &  \\
      &   & W
  \end{bmatrix}
  \begin{bmatrix}
    r \\ s \\ t
  \end{bmatrix}
\eqno
\usebox{\labelbox}
\]

[\ref{aa}]
[\ref{bb}]
[\ref{cc}]
\end{document}
David Carlisle
  • 757,742
  • Very interesting (and potentially useful) technique. Is there anything that can go wrong with it? – Steven B. Segletes May 10 '14 at 02:01
  • I didn't think of that. I like it! Why do you say it's not supported?It's not inelegant. – Dominique May 10 '14 at 04:30
  • \eqno is a TeX primitive and wouldn't generally work in conjunction with amsmath constructs, but you get away with it here. Probably you could (and should) use \tag in other contexts. – David Carlisle May 10 '14 at 10:04
  • @StevenB.Segletes something can go wrong with anything:-) \eqno shouldn't be used in latex (and wouldn't work in most ams math constructs) but it works here and I was getting tired:-) – David Carlisle May 10 '14 at 10:06
  • But you know me. I'm not contemplating using in with ams math constructs, but rather with TABstacks ;^) – Steven B. Segletes May 10 '14 at 11:10
  • I guess now I'm not sure how to assign labels to the equation numbers so as to refer to them individually?! – Dominique May 12 '14 at 20:54
  • @Dominique put \label{foo} immediately after \refstepcounter{equation} – David Carlisle May 12 '14 at 20:55
  • @DavidCarlisle But that gives me Package amsmath Error: Multiple \label's: label 'eq:gen-eig' will be lost. – Dominique May 12 '14 at 21:03
  • @Dominique sorry: try now I updated the answer with a workaround where you use the labeled numbers in a box before the equation. – David Carlisle May 12 '14 at 21:14
  • @SvendTveskæg - David Carlisle (and some other frequent contributors this site too...) prefer not to capitalize most words. Is there a need to teach David a different set of spelling rules by editing their postings? – Mico May 12 '14 at 22:07
  • @Mico Do you really thing I'm trying to teach David something? I probably can't teach him anything. But don't worry; I won't edit posts in the future. – Svend Tveskæg May 12 '14 at 22:24
  • @Mico I don't think you can ping him from here unless he's in the comment thread:-) But yes not capitalising latex is more or less intentional (although I'm not barabara:-) – David Carlisle May 12 '14 at 22:24
  • @SvendTveskæg oh you are there:-) Did mico's ping work or were you passing by? – David Carlisle May 12 '14 at 22:25
  • @DavidCarlisle His ping worked just fine. :) – Svend Tveskæg May 12 '14 at 22:25
  • @DavidCarlisle Many thanks! It even works with subequations. Much easier to read block equations in my opinion. – Dominique May 12 '14 at 22:28
  • @SvendTveskæg Odd @ s now offers your name now you are in the thread but if you were "just" here as editor it doesn't offer your name and I though @ ping didn't work in that case. As for editing my typing is pretty appalling so in general I don't mind people editing my text (although I tend not to use the logo capitalisation:-) – David Carlisle May 12 '14 at 22:29
  • @Mico ...and I mean ever change anything in other peoples' posts again when I get accused of stuff like that. – Svend Tveskæg May 13 '14 at 01:22
  • @SvendTveskæg - I'm concerned now that my initial comment got over- and mis-interpreted: It's just that some people have their own particular capitalization habits, and "correcting" the results will probably not change those habits, right? I'm in the habit of editing postings that contain clear typos (and I'm glad when other correct my typos!), but I don't tackle capitalization matters. Let's delete these comments now -- you go first! – Mico May 13 '14 at 05:22
0

Below there is a possible quick and dirty alternative if one needs AMS-\tags. The drawback is that it requires some manual height adjustment in the first matrix. This solution would not exist without the solution of David. Thanks, David! I needed this too.

\documentclass{article}
\usepackage{amsmath}
\begin{document}
\par\noindent\begin{minipage}[c][][c]{0.9\textwidth}
  \begin{align*}
  \begin{matrix}
    1\cdot x_1&+&2\cdot x_2&+&3\cdot x_3&=&4\\[3pt]
    5\cdot x_1&+&6\cdot x_2&+&7\cdot x_3&=&8\\[3pt]
    9\cdot x_1&+&10\cdot x_2&+&11\cdot x_4&=&12
  \end{matrix}
  \end{align*}
\end{minipage}\begin{minipage}[c][][c]{0.1\textwidth}
  \begin{align}\refstepcounter{equation}
    \tag{\theequation a}\label{eq:1a}\\[0pt]
    \tag{\theequation b}\label{eq:1b}\\[0pt]
    \tag{\theequation c}\label{eq:1c}    
  \end{align}
\end{minipage}
\end{document}

enter image description here

Troy
  • 13,741
Tobias
  • 155
0

By accident I discovered a simple and straight-forward way. If one has some large column in the actual matrix one should set a corresponding phantom in the numeration matrix. One could also add a \displaystyle in the equation number matrix if that is really needed.

\documentclass{article}
\usepackage{amsmath}
\makeatletter
\newcommand{\ltxlabel}{\ltx@label}
\makeatother
\begin{document}
\begin{align}\refstepcounter{equation}
  \begin{bmatrix}
    H            & J^T       & -Z^{\frac12} \\
    J            & -\delta I &              \\
    -Z^{\frac12} &           & -X
  \end{bmatrix}
  \begin{bmatrix}
    r \\ s \\ t
  \end{bmatrix}
  =
  \lambda
  \begin{bmatrix}
    H &   &  \\
    & U &  \\
    &   & W
  \end{bmatrix}
  \begin{bmatrix}
    r \\ s \\ t
  \end{bmatrix}
  \tag*{$\begin{matrix}
      \text{(\theequation a)}\\
      \text{(\theequation b)}\\
      \text{(\theequation c)}
    \end{matrix}$}
  \ltxlabel{eq:matrix}
\end{align}
The first row (\ref{eq:matrix}a) is the most important row of the matrix.
\end{document}

enter image description here

Tobias
  • 155
0

Here's a way to manually avoid the need to manipulate the counter. I create two \vboxes. The first is an array of blank subequations, and the second is the desired matrix in a simple \[...\] construct. Then I stack the two \vboxes atop each other. Voila!

I've even set it up so that adjusting the vertical baselineskip of the matrix (since I used TABstacks) is automatically reflected in the vertical separation of the equation numbering (through the use of the \aligngap macro).

One could, if desired, replace my TABstacks with {bmatrix}es and it would still work, though the definition of \aligngap would in that case, need some tweaking.

\documentclass{article}
\usepackage{amsmath,tabstackengine,lipsum}
\newsavebox\boxA
\def\aligngap{\dimexpr\Lstackgap-15pt\relax}
\begin{document}
\lipsum[1]

{\setstackgap{L}{14pt}% SELECTABLE MATRIX ROW BASELINESKIP
\setbox0=\vbox{\begin{subequations}%
  \begin{align}\label{eq:A}\\[\aligngap]\label{eq:B} \\[\aligngap]\label{eq:C}\end{align}%
  \end{subequations}}
\savebox\boxA{\vbox{\[
  \setstacktabbedgap{5pt}
  \bracketMatrixstack{
    H            & J^T       & -Z^{\frac12} \\
    J            & -\delta I &              \\
    -Z^{\frac12} &           & -X}
  \bracketVectorstack{r \\ s \\ t}
  =
  \lambda
  \bracketMatrixstack{
    H &   &  \\
      & U &  \\
      &   & W}
  \bracketVectorstack{r \\ s \\ t}
\]}}
\noindent\stackengine{3.5pt}{\box0}{\usebox{\boxA}}{O}{c}{F}{F}{L}}

In equations \ref{eq:A}, \ref{eq:B}, and \ref{eq:C},
\lipsum[2]
\end{document}

enter image description here