0

I would like to automatically be able to label and reference parts of equations. To explain what I mean I'll provide an example.

\documentclass{article}
\usepackage{amsmath,hyperref,cleveref}
\begin{document}
\begin{align}
     w&=x   &
     y&=z
     \label{eqn:full}
     \mylabel{eqn:wx}{a}
     \mylabel{eqn:yz}{b}
\end{align}
We're talking about \cref{eqn:full}, specifically \cref{eqn:wx}.
\end{document}

The text should read

We're talking about (1), specifically (1a).

How do I define \mylabel in order to achieve this? Of course I could use multiline equations, for example

\documentclass{article}
\usepackage{amsmath,hyperref,cleveref}
\begin{document}
\begin{subequations}\label{eqn:full}\begin{align}
     w&=x   \label{eqn:wx}\\
     y&=z   \label{eqn:yz}
\end{align}\end{subequations}
We're talking about \cref{eqn:full}, specifically \cref{eqn:wx}.
\end{document}

However, what I want is to be able to have all the equations on the same line to save space when the equations are very small. Another solution would be to simply add the >a into the text, but then if I reorder the subequations things get messy. It's ok if the equations only apear with a (1) next to them in the text, its the referencing I'm interested in.

Edit: an example that shows my issue

\documentclass{article}
\usepackage{amsmath,hyperref,cleveref,multicol}
\DeclarePairedDelimiter{\shock}{[}{]_{-}^{+}}
\begin{document}
\begin{subequations}\begin{multicols}{2}
     \begin{equation}
          \shock*{(u-s) h} = 0   \label{eqn:part1}\\
     \end{equation}
     \break
     \begin{equation}
          \shock*{(u-s)^2 h + \frac{h^2}{2}} = 0  \label{eqn:part2}\\
     \end{equation}
\end{multicols}\end{subequations}
We're talking about \cref{eqn:full}, specifically \cref{eqn:part1}.
\end{document}

Edit2: Final version of command

%Multiple labeled equations on same line
\newcommand{\sidebysidesubequations}[7]{
% #1    reference label
% #2    left subequation
% #3    left label
% #5    midtext
% #6    right subequation
% #7    right label
\begin{subequations}\label{#1}
    \noindent
    \begin{tabular}{@{}p{0.45\linewidth}@{}p{0.55\linewidth}@{}}
        \begin{equation}
            #2  \vphantom{\textrm{#4} \quad #5} \label{#3}
        \end{equation}%
        &
        \begin{equation}
             \textrm{#4} \qquad #5 \vphantom{#2}        \label{#6}
        \end{equation}%
    \end{tabular}
\end{subequations}
}
Eddy
  • 291

1 Answers1

2

A very minor adaption from this answer. Note that Gonzalo Medina's answer using minipages is better if you wish to adapt the width of each subequation.

\documentclass{article}
\usepackage{amsmath,hyperref,cleveref}
\usepackage{multicol}
\begin{document}

\begin{subequations}\label{eqn:full}
    \begin{multicols}{2}
        \begin{equation}
            w=x   \label{eqn:wx}
        \end{equation}\break
        \begin{equation}
            y=z   \label{eqn:yz}
        \end{equation}
    \end{multicols}
\end{subequations}

We're talking about \cref{eqn:full}, specifically \cref{eqn:wx}.
\end{document}

enter image description here

EDIT

Due to the vertical alingment problem, it feels like a tabularx/vphantom -based solution is more relevant. Basically, both cells of the tabularx share the same height due to the

contentcell1 \vphatom{contentcell2} 

structure.

I wrapped all the code into a newcommand to ease the use.

\documentclass{article}
\usepackage{mathtools,hyperref,cleveref,tabularx}
\DeclarePairedDelimiter{\shock}{[}{]_{-}^{+}}

\newcommand{\sidebysidesubequations}[3]{%
% 1st argument is the reference label
% 2nd argument is the left subequation
% 3rd argument is the right subequation
% Sublabels are defined with suffixes -left and -right
    \begin{subequations}\label{#1}
        \noindent
        \begin{tabularx}{\linewidth}{XX}
         \begin{equation}
              #2 \vphantom{#3}  \label{#1-left}
         \end{equation}%
         &
         \begin{equation}
              #3 \vphantom{#2} \label{#1-right}
         \end{equation}
    \end{tabularx}
    \end{subequations}
}

\begin{document}
\sidebysidesubequations{eqn:full}{
    \shock*{(u-s) h} = 0
}{
    \shock*{(u-s)^2 h + \frac{h^2}{2}} = 0
}
We're talking about \cref{eqn:full}, specifically \cref{eqn:full-left}.
\end{document}

enter image description here

BambOo
  • 8,801
  • 2
  • 20
  • 47
  • @Eddy, I have a feeling, that it may not be what you really ask for. You say you want to label parts of equations, but your maths shows two equations. The answer above is not automatic per se, but has the two references and both equations are on the same line. – BambOo Apr 03 '20 at 17:29
  • Thanks for your respnse. The issue with the solutions cited question is that they mess up the vertical alignment that the align environment gives. Using this solution in my actual document results in the (1a) and (1b) not being vertically aligned... – Eddy Apr 06 '20 at 10:08
  • @Eddy, could you update your MWE sot that it shows this issue ? – BambOo Apr 06 '20 at 15:30
  • added a new example – Eddy Apr 06 '20 at 15:39
  • @Eddy I updated my answer. Be careful when you write an MWE to be sure that it compiles. For instance amsmat does not provide DeclarePairedDelimiter, mathtools does. – BambOo Apr 06 '20 at 16:30
  • thanks for your help, it seems it was \vphantom I needed to know! – Eddy Apr 07 '20 at 11:58
  • You're welcome ! – BambOo Apr 07 '20 at 13:00