
我在用這個答案自動發現對齊線。不過,我想提醒大家注意揭露。
我不知道 expl3 並且我嘗試破解上面引用的答案失敗了:我嘗試調整該答案以將其包裝\onslide
如下\alert<+>{}
:
\alert<+>{\onslide<+->{ ##1 \\ }}
但我收到一個錯誤:
! Extra }, or forgotten \endgroup.
我也嘗試過將其放在\alert<+>{}
裡面:
\tl_put_right:Nn \l_tmpa_tl { \onslide<+->{ \alert<+>{ ##1 } } \\ }
但我得到同樣的錯誤:
! Extra }, or forgotten \endgroup.
比內部硬編碼更強大的解決方案\alert
是能夠在更高層級設定覆蓋策略。我在下面的範例的評論中提到了這一點。但如果這是不可能的,我會很高興使用硬編碼的\alert
.
顯示目前行為的範例。我希望範例中的對齊行為與逐項排列行為類似。
\documentclass{beamer}
\let\oldalign\align
\let\endoldalign\endalign
% https://tex.stackexchange.com/a/611688/12212
\ExplSyntaxOn
\NewDocumentEnvironment{myalign}{+b}
{
\tl_set:Nn \l_tmpa_tl { \begin{oldalign} }
\seq_set_split:Nnn \l_tmpa_seq { \\ } {#1}
\seq_map_inline:Nn \l_tmpa_seq
{
\tl_if_empty:nF { ##1 }
{
\tl_put_right:Nn \l_tmpa_tl { \onslide<+->{ ##1 \\ } }
}
}
\tl_put_right:Nn \l_tmpa_tl { \notag \end{oldalign} \vskip-1.5em }
\l_tmpa_tl
} { }
\ExplSyntaxOff
\newenvironment{overlayalign}
{
\renewenvironment{align}{%
\begin{myalign}
}{%
\end{myalign}
}
}
{
}
\begin{document}
\begin{frame}[<alert@+|+->]
% I generally prefer the alert, but it would be nice to be able to change to
% the following, and align adapts (i.e., would not alert), just like itemize:
%\begin{frame}[<+->]
I would like behavior similar to itemize:
\begin{itemize}
\item one
\item two
\item three
\end{itemize}
\begin{overlayalign}
\begin{align}
abc & = def \\
& = ghi \\
& = jkl \\
& = 0. \\
\end{align}
\end{overlayalign}
\end{frame}
\end{document}
答案1
這是使用 L3 程式設計層的方法
\documentclass{beamer}
\ExplSyntaxOn
\seq_new:N \l__myalign_linesin_seq
\seq_new:N \l__myalign_linesout_seq
\seq_new:N \l__myalign_onelinein_seq
\seq_new:N \l__myalign_onelineout_seq
\NewDocumentEnvironment{myalign}{+b}
{
\exp_after:wN \cs_set_nopar:Npn \cs:w tagform@ \cs_end: ##1
{
\cs:w maketag@@@ \cs_end:
{
\action<.-|alert@.> { ( \ignorespaces ##1 \unskip \cs:w @@italiccorr \cs_end: ) }
}
}
\seq_set_split:Nnn \l__myalign_linesin_seq { \\ } { #1 }
\seq_map_inline:Nn \l__myalign_linesin_seq
{
\seq_clear:N \l__myalign_onelineout_seq
\seq_set_split:Nnn \l__myalign_onelinein_seq { & } { ##1 }
\seq_map_indexed_inline:Nn \l__myalign_onelinein_seq
{
\int_compare:nNnTF { ####1 } = { 1 }
{ \seq_put_right:Nn \l__myalign_onelineout_seq { \action<+-|alert@+> { ####2 } } }
{ \seq_put_right:Nn \l__myalign_onelineout_seq { \action<.-|alert@.> { ####2 } } }
}
\seq_put_right:Nx \l__myalign_linesout_seq { \seq_use:Nnnn \l__myalign_onelineout_seq { & } { & } { & } }
}
\begin{align}
\seq_use:Nnnn \l__myalign_linesout_seq { \\ } { \\ } { \\ }
\end{align}
} { }
\ExplSyntaxOff
\begin{document}
\begin{frame}[<alert@+|+->]
I would like behavior similar to itemize:
\begin{itemize}
\item one
\item two
\item three
\end{itemize}
\begin{myalign}
abc & = def \\
& = ghi \\
& = jkl \\
& = 0.
\end{myalign}
\visible<+->{test}
\end{frame}
\end{document}
答案2
一種不同的方法使用tabularray
:
\documentclass{beamer}
\usepackage{tabularray}
\UseTblrLibrary{counter}
\NewDocumentEnvironment{myalign}{+b}{
\begin{tblr}{
column{1}={co=1},
column{Z}={co=1},
column{odd}={halign=r},
column{even}={halign=l},
colsep = 0pt,
cells={mode=dmath},
cell{1-Z}{1}={cmd=\action<+-|alert@+>},
cell{1-Z}{2-Z}={cmd=\action<.-|alert@.>},
cell{1-Z}{Z}={appto={\hfill \refstepcounter{equation}(\theequation)}}
}
#1
\end{tblr}
}{}
\begin{document}
\begin{frame}[<alert@+|+->]
I would like behavior similar to itemize:
\begin{itemize}
\item one
\item two
\item three
\end{itemize}
\begin{myalign}
abc & = def \\
& = ghi \\
& = jkl \\
& = 0. \\
\end{myalign}
\visible<+->{test}
\end{frame}
\end{document}