I want to make a subnumcases
-like environment, named mynumcases
, like this
I will explain what I want and what I have tried.
- what I want:
- equations in
mynumcases
have a parent counter which is same asequation
- I want to put this parent counter before the big brace, and has a fixed length away from left margin (I don't know what the left line's name), this length doesn't need to set as an argument.
\Roman
parent counter and\alph
child counter- (option) I can make my own tag at the position of the parent counter
-
what I have tried
- I refered this answer: https://tex.stackexchange.com/a/343157/180617
- I found I can't use this method in my demand.
- I tried to use
empheq
package's[left=...]
argument.
Here is my code:
\documentclass{article}
\usepackage{amsmath, environ}
\usepackage{empheq}
\usepackage[showframe]{geometry}
\makeatletter
\def\Rom{\@Roman}
\NewEnviron{mynumcases}[2][\@nil]{%
\def\tmp@ne{#1}
\refstepcounter{equation}
\edef\oldeqnum{\theequation}
\setcounter{equation}{0}
\renewcommand{\theequation}{\alph{equation}}
\begin{empheq}[left={\makebox[0pt][r]{\makebox[.3\linewidth][l]{\ifx\tmp@ne\@nnil (\Rom{\oldeqnum}) \else #1 \fi}}#2\empheqlbrace}]{align}
\BODY
\end{empheq}
\setcounter{equation}{\oldeqnum}
}
\makeatother
\begin{document}
first equation
\begin{equation}
1 + 1 = 2
\end{equation}
first mynumcases
\begin{mynumcases}{}
& 1 + 1 = 2\\
& 1 = 1
\end{mynumcases}
another equation
\begin{equation}
test
\end{equation}
second mynumcases
\begin{mynumcases}{f(x)=}
& 1+1+1+1+1 & \text{if } hello\\
& 1 + 1 & \text{if } hello\\
& 1 & \text{if } hello\\
& 1
\end{mynumcases}
third mynumcases
\begin{mynumcases}[my words]{f(x)=}
& 1+1+1+1+1\\
& 1 + 1\\
& 1
\end{mynumcases}
\end{document}
and the whole output
And we can notice that
- the parent counter has the fixed length away from the equation, not left margin
- I have to put
&
before every line to make it align left if hello
is far away from1+1..
How can I reach my demand? Does anyone have ideas?
Best Answer
Here is the process I followed to achieve the requested solution:
Store the coordinate of the left margin using
eso-pic
andzref
'ssavepos
module. We place a "label"lm
at the start of the first page in the lower left corner of the text block. We'll use this x-coordinate in a calculation when setting any labels formynumcases
.Insert the appropriate equation label (either the optional argument or the actual equation number in
\Roman
) via\inserteqnum
, by......inserting an appropriately-sized box to the left of
empheq
based on the location of the argument passed toempheq
. The calculations use an equation-specific x-coordinate marker (also thanks tozref
'ssavepos
module), the aforementionedl
eftm
argin x-coordinate and a predefined\empheqnumindent
length that sets it off from the left margin.Since this approach uses (La)TeX's
\label
-\ref
-like system, any change in the page dimensions (technically, the left margin on the first page) or themynumcases
width would require an additional compilation.This approach can be adapted for
twoside
more, or arbitrary page layouts. The approach would be to insert an page-specificl
eftm
argin marker rather than just one at the start of the document.