I'd insert an equation within a figure as shown in the following image.
I'd like also to visualize the number that identifies the equation.
Is it possible to obtain what I've written?
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It only takes a minute to sign up.
Sign up to join this communityI'd insert an equation within a figure as shown in the following image.
I'd like also to visualize the number that identifies the equation.
Is it possible to obtain what I've written?
If you save the equation in a boxed minipage \sbox2
, you can \stackinset
it into the figure.
\documentclass{article}
\usepackage{stackengine,graphicx}
\begin{document}
\begin{equation}
E=mc^1
\end{equation}
\begin{figure}[ht]
\sbox2{\begin{minipage}{100pt}
\begin{equation}
E=mc^2
\end{equation}
\end{minipage}}
\stackinset{r}{20pt}{t}{20pt}{\copy2}
{\includegraphics[width=\textwidth]{example-image}}
\caption{My caption}
\end{figure}
\begin{equation}
E=mc^3
\end{equation}
\end{document}
UPDATE
At the urging of Don in comments below, I have updated the stackengine
package so that one may bypass the creation of the intermediate box2. Instead, one may place the content directly into the \stackinset
without adverse effects on the equation
counter. It should propagate in a few days, I hope. It is v4.1 2021-07-15
\documentclass{article}
\usepackage{stackengine}[2021-07-15]
\usepackage{graphicx}
\begin{document}
\begin{equation}
E=mc^1
\end{equation}
\begin{figure}[ht]
\stackinset{r}{20pt}{t}{20pt}
{\begin{minipage}{100pt}\begin{equation}
E=mc^2
\end{equation}\end{minipage}}
{\includegraphics[width=\textwidth]{example-image}}
\caption{My caption}
\end{figure}
\begin{equation}
E=mc^3
\end{equation}
\end{document}
\stackinset
typesets its contents 5 times? I thought the whole \sbox
…\copy
smelled a bit odd when I saw it, but I thought to try it modified before commenting—is there some compelling reason to keep re-interpretting the argument of \stackinset
? I haven't had a chance to look at the code yet.
Jul 6, 2021 at 3:23
#5
and #6
in boxes rather than macros. It's a lot faster for TeX to do a \copy\somebox
than to re-parse the tokens from #5
and #6
repeatedly. It's kind of expensive to look in graphics files to get the dimensions, not to mention side effects if there are numbered structures in one of the arguments. If you like, I can give you a PR with my suggested changes.
Jul 6, 2021 at 3:33
\includegraphics
multiple times, it only goes through the process the first time, and re-uses information for subsequent calls. Nonetheless, your argument applies even to non-graphical load (such as \begin{equation}
)s, so I should consider it for that reason alone. Thanks for the reminder!
Jul 6, 2021 at 8:55
stackengine
. Not only does it only evaluate the arguments but once, both for efficiency and so that counters action in the argument doesn't get out of sync, but I also improved the ability to perform nesting (which was sadly deficient for stacks involving field separators, rather than explicit arguments). It should distribute in a few days, I suppose.
Jul 15, 2021 at 14:39