
我試圖將矩陣插入到 \subsection{} 中:
\subsection{Suppose $X= \begin{array}{cc}
1 & 2 \\
3 & 4
\end{array}$}
這給了我一個錯誤:
! TeX capacity exceeded, sorry [input stack size=5000].
這裡有什麼問題嗎?謝謝!
答案1
我猜你想要smallmatrix
而不是array
。但如果您確實願意,也可以使用全尺寸版本。
關鍵是\begin
、\end
和\\
很脆弱,因此\protect
在移動參數(章節標題或標題)中需要放在它們前面。
\documentclass{article}
\usepackage{amsmath}
\begin{document}
\subsection{Suppose $X=\left[\protect\begin{smallmatrix}
1 & 2 \protect\\
3 & 4
\protect\end{smallmatrix}\right]$}
\subsection{Suppose $X=\protect\begin{bmatrix}
1 & 2 \protect\\
3 & 4
\protect\end{bmatrix}$}
\end{document}
答案2
如果您還需要在目錄中顯示矩陣,可以使用下列一種技術:
\documentclass{article}
\usepackage{tabstackengine}
\setstacktabbedgap{1ex}
\savestack{\mathexpr}{$X= \bracketMatrixstack{1 & 2 \\3 & 4}$}
\begin{document}
\tableofcontents
\section{Main Topic}
\subsection{Suppose \mathexpr}
\section{Next Topic}
\end{document}