我想要输入这个:
我开始这样做
\begin{subequations}
\begin{equation}
0. \text{la la la } 0 + 1 = 1
\end{equation
\begin{equation}
1. he he he
\end{equation}
\end{subequations
但我认为这不是一个好方法。
该算法的结构是怎样的?
答案1
适合老人的工作tabbing
:
\documentclass{article}
\usepackage{amsmath,amsthm}
\newtheoremstyle{mystyle}% <name>
{\topsep}% <space above>
{\topsep}% <space below>
{\normalfont}% <body font>
{}% <indent amount>
{\bfseries}% <theorem head font>
{}% <punctuation after theorem head>
{.5em}% <space after theorem head>
{}% <theorem head spec>
\theoremstyle{mystyle}
\newtheorem{algorithm}{Algorithm}[section]
\newcommand{\algoqed}{%
\makebox[0pt][l]{%
\makebox[\textwidth][r]{\rule{0.4em}{0.7em}}%
}%
}
\newcounter{algostep}
\newlength{\stepwidth}
\newcommand{\step}{%
\refstepcounter{algostep}%
\makebox[\stepwidth][r]{\thealgostep. }%
}
\newcommand{\initialstep}[2][1]{%
\setcounter{algostep}{#2}%
\addtocounter{algostep}{-1}%
\settowidth{\stepwidth}{#1. }%
}
\begin{document}
\setcounter{section}{6} %just for the example
\setcounter{algorithm}{1} %just for the example
\begin{algorithm}
\initialstep[10]{0}
The Preconditioned Conjugate Gradient Method for Solving the Symmetric
Positive Definite System $Ax = b$, Starting with $x^{(0)}$
\begin{tabbing}
\step
\= Input stopping criteria, $\epsilon$ and $k_{\text{max}}$.\\
\> Set $k=0$, $r^{(k)}=b-Ax^{(k)}$, $s=Ar^{(k)}$,
$p=M^{-1}s^{(k)}$, $y^{(k)}=M^{-1}r^{(k)}$\\
\> and $\gamma^{(k)}=y^{(k)\mathrm{T}}s^{(k)}$.\\
\step\label{step1}
\> If $\gamma^{(k)}\le\epsilon$, set $x=x^{(k)}$ and terminate.\\
\step
\> Set $q^{(k)}=Ap^{(k)}$.\\
\step
\> Set $\alpha^{(k)}=\frac{\gamma^{(k)}}{\|q^{(k)}\|^2}$.\\
\step
\> Set $x^{(k+1)}=x^{(k)}+\alpha^{(k)}p^{(k)}$.\\
\step
\> Set $r^{(k+1)}=r^{(k)}-\alpha^{(k)}q^{(k)}$.\\
\step
\> Set $s^{(k+1)}=A^{(k+1)}$.\\
\step
\> Set $y^{(k+1)}=M^{-1}r^{(k+1)}$.\\
\step
\> Set $\gamma^{(k+1)}=y^{(k+1)\mathrm{T}}s^{(k+1)}$.\\
\step
\> Set $p^{(k+1)}=M^{-1}s^{(k+1)}+\frac{\gamma^{(k+1)}}{\gamma^{(k)}}p^{(k)}$.\\
\step
\> If \= $k<k_{\text{max}}$,\\
\> \> set $k\gets k + 1$ and go to step \ref{step1};\\
\> otherwise\\
\> \> issue message that\\
\algoqed
\> \> ``algorithm did not converge in $k_{\text{max}}$ iterations''.
\end{tabbing}
\end{algorithm}
\end{document}
用\initialstep[<final>]{<initial>}
1 来设置初始和最终步骤数(实际上<final>
仅用于数字位数,默认为 1)。算法中的步骤由 引入,\step
后面可以跟\label
。第一个\step
后面是\=
设置制表位。
最后一行可以加上\algoqed
黑框作为前缀。
我会避免使用粗体字样;标题足以突出它。我保留了原来的大写字母,但它确实很难看。
答案2
恕我直言,它是用这样的方法完成的
\documentclass{article}
\usepackage{amsmath,amsthm,enumitem}
\newtheoremstyle{mystyle}% <name>
{\topsep}% <space above>
{\topsep}% <space below>
{\bfseries}% <body font>
{}% <indent amount>
{\bfseries}% <theorem head font>
{}% <punctuation after theorem head>
{.5em}% <space after theorem head>
{}% <theorem head spec>
\theoremstyle{mystyle}
\newtheorem{algorithm}{Algorithm}[section]
\renewcommand{\qedsymbol}{\rule{0.4em}{0.7em}}
\setlist[enumerate]{%
parsep=0pt,
leftmargin=1.25\parindent,
listparindent=\parindent
}
\begin{document}
\setcounter{section}{6} %just for the example
\setcounter{algorithm}{1} %just for the example
\begin{algorithm}
The Preconditioned Conjugate Gradient Method for Solving the Symmetric
Positive Definite System $Ax = b$, Starting with $x^{(0)}$
\end{algorithm}
\begin{enumerate}
\setcounter{enumi}{-1}
\item Input stopping criteria, $\epsilon$ and $k_{\text{max}}$.\\
Set...
\item ...
\setcounter{enumi}{9} %just for the example
\item If $k<k_{\text{max}}$,\\
\indent set k = k + 1 and go to step 1;\\
otherwise\\
\indent issue message that\\
\indent ``algorithm did not converge in $k_{\text{max}}$ iterations''.\qed
\end{enumerate}
\end{document}