![如何使用 cnltx-example 編寫矩陣及其原始程式碼](https://rvso.com/image/399972/%E5%A6%82%E4%BD%95%E4%BD%BF%E7%94%A8%20cnltx-example%20%E7%B7%A8%E5%AF%AB%E7%9F%A9%E9%99%A3%E5%8F%8A%E5%85%B6%E5%8E%9F%E5%A7%8B%E7%A8%8B%E5%BC%8F%E7%A2%BC.png)
我想得到矩陣的輸出
\begin{pmatrix}
\frac{1}{2} & 0 & \frac{9}{5} \\
-2 & \frac{2}{3} & -\frac{1}{4} \\
12 & 0 & \frac{11}{7} \\
\end{pmatrix}
以及並排顯示的程式碼
\begin{example}[side-by-side]
\end{example}
帶cnltx-example
包。當我要編譯(使用amsart
文檔類別)這個時,它給了一個錯誤。如何解決這個問題?
這是我的程式碼
\documentclass{amsart}
\usepackage{amsmath,amsthm,amssymb,amsxtra,amsopn}
\usepackage{cnltx-example}
\begin{document}
\begin{example}[side-by-side]
Consider the following example.
\[ (x + y)^2 = x^2 + 2xy + y^2\]
\end{example}
%The following gives an error at the time of compiling
\begin{example}[side-by-side]
Consider the following matrix.
$\begin{pmatrix}
\frac{1}{2} & 0 & \frac{9}{5} \\
-2 & \frac{2}{3} & -\frac{1}{4} \\
12 & 0 & \frac{11}{7} \\
\end{pmatrix}$
\end{example}
\end{document}
答案1
顯然,cnltx-example
需要將程式碼縮排兩個空格:
\documentclass{amsart}
\usepackage{amssymb}
\usepackage{cnltx-example}
\begin{document}
\begin{example}[side-by-side]
Consider the following example.
\[ (x + y)^2 = x^2 + 2xy + y^2\]
\end{example}
%The following gives an error at the time of compiling
\begin{example}[side-by-side]
Consider the following matrix.
$\begin{pmatrix} \frac{1}{2} & 0 & \frac{9}{5} \\
-2 & \frac{2}{3} & -\frac{1}{4} \\
12 & 0 & \frac{11}{7} \\
\end{pmatrix}$
\end{example}
\end{document}