![复杂矩阵布局在 beamer 中失败,但在 MWE 中可以](https://linux22.com/image/310827/%E5%A4%8D%E6%9D%82%E7%9F%A9%E9%98%B5%E5%B8%83%E5%B1%80%E5%9C%A8%20beamer%20%E4%B8%AD%E5%A4%B1%E8%B4%A5%EF%BC%8C%E4%BD%86%E5%9C%A8%20MWE%20%E4%B8%AD%E5%8F%AF%E4%BB%A5.png)
下面的 MWE 可以很好地布局这个复杂的矩阵。但是当我将其粘贴到一个简单的 beamer 文档中时,它失败了(我还包含了该代码,你能帮助我吗?
\documentclass[12pt,a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage{amsmath,adjustbox}
\usepackage{amsfonts}
\begin{document}
\newenvironment{Pbmatrix}[1][c]
{\begin{adjustbox}{valign=#1}$\begin{pmatrix}}
{\end{pmatrix}$\end{adjustbox}}
\newcommand{\matt}[5]{
\begin{pmatrix}
\begin{Pbmatrix}[b]
2+r_1 & -1 \\
-1 & 2+r_1 & -1 \\
& \ddots & \ddots & \ddots \\
& & \ddots & \ddots & \ddots \\
& & & -1 & 2+r_1 & -1 \\
& & & & -1 & 2+r_1 \\
\end{Pbmatrix} & #3 \\
\hfill #4 & #1 & #2\hfill \\
& #5 & \begin{Pbmatrix}[t]
2+r_2 & -1 \\
-1 & 2+r_2 & -1 \\
& \ddots & \ddots & \ddots \\
& & \ddots & \ddots & \ddots \\
& & & -1 & 2+r_2 & -1 \\
& & & & -1 & 2+r_2 \\
\end{Pbmatrix}
\end{pmatrix}
}
\begin{equation*}
\resizebox{\linewidth}{!}{%
$\mathbf{A_{if}}=\matt {K_1/h_1+K_2/h_2} {-K_2/h_2} {-1} {-K_1/h_1} {-1}$
}
\end{equation*}
\end{document}
这个 Beamer 文档不起作用。
\documentclass[11pt]{beamer}
\usetheme{Warsaw}
\usepackage[utf8]{inputenc}
\usepackage{amsmath,adjustbox,mathtools}
\usepackage{amsfonts}
\begin{document}
\begin{frame}
\newenvironment{Pbmatrix}[1][c]
{\begin{adjustbox}{valign=#1}$\begin{pmatrix}}
{\end{pmatrix}$\end{adjustbox}}
\newcommand{\matt}[5]{
\begin{pmatrix}
\begin{Pbmatrix}[b]
2+r_1 & -1 \\
-1 & 2+r_1 & -1 \\
& \ddots & \ddots & \ddots \\
& & \ddots & \ddots & \ddots \\
& & & -1 & 2+r_1 & -1 \\
& & & & -1 & 2+r_1 \\
\end{Pbmatrix} & #3 \\
\hfill #4 & #1 & #2\hfill \\
& #5 & \begin{Pbmatrix}[t]
2+r_2 & -1 \\
-1 & 2+r_2 & -1 \\
& \ddots & \ddots & \ddots \\
& & \ddots & \ddots & \ddots \\
& & & -1 & 2+r_2 & -1 \\
& & & & -1 & 2+r_2 \\
\end{Pbmatrix}
\end{pmatrix}
}
\begin{equation*}
\resizebox{\linewidth}{!}{%
$\mathbf{A_{if}}=\matt {K_1/h_1+K_2/h_2} {-K_2/h_2} {-1} {-K_1/h_1} {-1}$
}
\end{equation*}
\end{frame}
\end{document}
答案1
命令和环境应该提前定义\begin{document}
,你可以在框架之间重新定义它们
\documentclass[11pt]{beamer}
\usetheme{Warsaw}
\usepackage[utf8]{inputenc}
\usepackage{amsmath,adjustbox,mathtools}
\usepackage{amsfonts}
\newenvironment{Pbmatrix}[1][c]
{\begin{adjustbox}{valign=#1}$\begin{pmatrix}}
{\end{pmatrix}$\end{adjustbox}}
\newcommand{\matt}[5]{
\begin{pmatrix}
\begin{Pbmatrix}[b]
2+r_1 & -1 \\
-1 & 2+r_1 & -1 \\
& \ddots & \ddots & \ddots \\
& & \ddots & \ddots & \ddots \\
& & & -1 & 2+r_1 & -1 \\
& & & & -1 & 2+r_1 \\
\end{Pbmatrix} & #3 \\
\hfill #4 & #1 & #2\hfill \\
& #5 & \begin{Pbmatrix}[t]
2+r_2 & -1 \\
-1 & 2+r_2 & -1 \\
& \ddots & \ddots & \ddots \\
& & \ddots & \ddots & \ddots \\
& & & -1 & 2+r_2 & -1 \\
& & & & -1 & 2+r_2 \\
\end{Pbmatrix}
\end{pmatrix}
}
\begin{document}
\begin{frame}
\begin{equation*}
\resizebox{\linewidth}{!}{%
$\mathbf{A_{if}}=\matt {K_1/h_1+K_2/h_2} {-K_2/h_2} {-1} {-K_1/h_1} {-1}$
}
\end{equation*}
\end{frame}
%----------------------- \matt redefined
\renewcommand{\matt}{notning}
\begin{frame}
\matt
\end{frame}
\end{document}