我正在尝试学习 LaTeX 宏编写,因此我正在创建一个类似列表的环境来排版证明(入门命题逻辑)。我可以通过这种方式获得不错的结果:
\documentclass{article}
\begin{document}
\begin{tabular}{r c l}
1. & $some math$ & Justification.\\
2. & $some math$ & Justification.\\
\end{tabular}
\end{document}
虽然看起来还不错,但仍存在一些问题:编号是手动的,在我组织它时不会重新计算,结构非常重复,并且不明显它应该是什么(在我看来)。
我想创建一个具有这种语法的环境:
\documentclass{article}
\begin{document}
\begin{proof}
\step some math & Justification.
\step some math & Justification.
\end{proof}
\end{document}
实现这一目标的最佳方法是什么(如果可能的话)?
编辑:澄清一下,我知道在表格中自动编号等操作。我真正需要帮助的是将命令后的文本\step
放入宏/环境中。
答案1
实际上,我最终使用了 3 列。这样我就可以在边界内显示数学。宏\step
和\reason
仅在证明环境中定义。请注意,我\theequation
在最右边的列中重新定义了步骤编号。
\documentclass{article}
\usepackage[leqno]{amsmath}
\usepackage{paracol}
\setcolumnwidth{\labelwidth,4cm}
\newcounter{step}
\globalcounter{step}
\newenvironment{proof}{\setcounter{step}{0}%
\parindent=0pt
\sloppy
\def\step{\switchcolumn[0]*[\medskip]%
\refstepcounter{step}%
\makebox[\columnwidth][r]{\textbf{\thestep.}}%
\switchcolumn[1]}%
\def\reason{\switchcolumn[2]
\setcounter{equation}{0}%
\renewcommand{\theequation}{\thestep.\arabic{equation}}}%
\paracol{3}}%
{\endparacol}
\begin{document}
\begin{proof}
\step some math \reason This shows what happens when text extends beyond one line.
\step This shows what happens when text extends beyond one line.
\begin{equation}x = a\end{equation}
\reason justification
\begin{equation}a = x\end{equation}
\step some math \reason justification
\end{proof}
\end{document}
答案2
tabular
您可以在proof
环境中包装一个,\step
转换为设置数字和列分隔符&
:
\documentclass{article}
\usepackage{tabularx}
\newcounter{proofstep}
\newcommand{\step}{}
\newenvironment{proofA}
{\par
\setcounter{proofstep}{0}%
\renewcommand{\step}{\refstepcounter{proofstep}\theproofstep. &}%
\noindent
\begin{tabular}{ @{} r c l @{}}}
{\end{tabular}}
\newenvironment{proofB}
{\par
\setcounter{proofstep}{0}%
\renewcommand{\step}{\refstepcounter{proofstep}\theproofstep. &}%
\noindent
\tabularx{\textwidth}{ @{} r c X @{} }}
{\endtabularx}
\begin{document}
\noindent
\begin{tabular}{ @{} r c l @{} }
1. & some math & Justification. \\
2. & some math & Justification.
\end{tabular}
\begin{proofA}
\step some math & Justification. \\
\step some math & Justification.
\end{proofA}
\begin{proofB}
\step some math & This is just another sentence that will span at least two lines. Well, now it will, for sure! \\
\step some math & Justification.
\end{proofB}
\end{document}
提供两种校样环境:proofA
和proofB
。第一种使用常规的tabular
,第二种使用tabularx
允许两端对齐的段落文本的。