下面的 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}