描述方程中的步骤

描述方程中的步骤

我总是描述如何实现公式的步骤或描述解决环境中的问题所采用的底层数学原理align。但描述并没有以最佳方式呈现。例如:

\documentclass[letterpaper]{article}
\usepackage{fullpage}
\usepackage{amsmath,amssymb,amsthm,enumitem}
\usepackage[dvipsnames]{xcolor}
\newcommand{\red}[1]{%
{\color{OrangeRed}#1}}

\begin{document}
Let us show that by completing the square, we can achieve this.
        \begin{align*}
        f(x)&=ax^2+bx+c \qquad\qquad\qquad\qquad\qquad\mbox{ Factor $a$ from $ax^2+bx$. Do you know why?}\\
            &=a\left(x^2+\frac{b}{a}x\right)+c\qquad\qquad\qquad\qquad\mbox{ \red{Complete the square by adding $\frac{b^2}{4a^2}$.}} \\
            &=a\left(x^2+\frac{b}{a}x+\red{\frac{b^2}{4a^2}} \right)+c\red{-a\left(\frac{b^2}{4a^2}\right)}\mbox{~~~Factor and simplify.}\\
            &=a\left(x+\frac{b}{2a}\right)^2+c-\frac{b^2}{4a}\\
            &=a\left(x+\frac{b}{2a}\right)^2+\frac{4ac-b^2}{4a}\\
            &=a(x-h)^2+k
        \end{align*}
 \end{document}

产量:

enter image description here

这无法正确显示描述。如果您注意到上面的代码,我会强制描述根据最长的数学显示行(找到的位置a\left(x^2+\frac{b}{a}x+\red{\frac{b^2}{4a^2}} \right)+c\red{-a\left(\frac{b^2}{4a^2}\right)})进行左缩进。

现在有一个不同的情况:

\documentclass[letterpaper]{article}
\usepackage{fullpage}
\usepackage{amsmath,amssymb,amsthm,enumitem}
\usepackage[dvipsnames]{xcolor}
\newcommand{\red}[1]{%
{\color{OrangeRed}#1}}

\begin{document}
Let us apply completing the square to the standard form of a quadratic equation, $ax^2+bx+c=0$.

\begin{align*}
    ax^2+bx+c&=0 &\mbox{Divide by $a$, the leading coefficient.}&\\[1.25ex]
    x^2+\frac{b}{a}x+\frac{c}{a}&=0 &\mbox{Transpose the constant term to the RHS.}&\\[1.25ex]
    x^2+\frac{b}{a}x&=-\frac{c}{a}&\mbox{\red{Add $\left(\frac{1}{2}\left(\frac{b}{a}\right)\right)^2$ to both sides.}}&\\[1.25ex]
    x^2+\frac{b}{a}x+\frac{b^2}{4a^2}&=-\frac{c}{a}+\frac{b^2}{4a^2}&\mbox{Factor the LHS and simplify the RHS.}&\\[1.25ex]
    \left(x+\frac{b}{a}\right)^2&=\frac{b^2-4ac}{4a^2}&\mbox{Take the square root of both sides.}&\\[1.25ex]
    x+\frac{b}{a}&=\pm\frac{\sqrt{b^2-4ac}}{2a}&\mbox{Solve for $x$.}&\\[1.25ex]
    x&=\frac{-b\pm\sqrt{b^2-4ac}}{2a}&\mbox{\textbf{Quadratic Formula}.}&
    \end{align*}
 \end{document}

得出的结果是:

enter image description here

但在本例中,描述是右对齐的,并且不依赖于最长的数学显示行。我曾在某处读到,使用

\text{\parbox[t]{2in}{ can be used in mathmode with a very long long long long long long long description}

当然,我预见到了一个缺点,因为长度parabox应该根据文本的剩余空间来计算,同时保持在边距内。

总之,我希望描述左对齐,并依赖于最长的数学显示或可能的分割(如果使用split数学方程式环境),并且如果描述超过一行,则转到第二行或第三行,并具有相同的正确缩进。任何有关此事的帮助都将不胜感激。

答案1

类似这样的事?(&&之前两个\mbox

\documentclass[letterpaper]{article}
\usepackage{fullpage}
\usepackage{amsmath,amssymb,amsthm,enumitem}
\usepackage[dvipsnames]{xcolor}
\newcommand{\red}[1]{%
  {\color{OrangeRed}#1}}

\begin{document}
Let us apply completing the square to the standard form of a quadratic equation, $ax^2+bx+c=0$.

\begin{align*}
  ax^2+bx+c&=0 &&\text{Divide by $a$, the leading coefficient.}&\\[1.25ex]
  x^2+\frac{b}{a}x+\frac{c}{a}&=0 &&\text{Transpose the constant term to the RHS.}&\\[1.25ex]
  x^2+\frac{b}{a}x&=-\frac{c}{a}&&\text{\red{Add $\left(\frac{1}{2}\left(\frac{b}{a}\right)\right)^2$ to both sides.}}&\\[1.25ex]
  x^2+\frac{b}{a}x+\frac{b^2}{4a^2}&=-\frac{c}{a}+\frac{b^2}{4a^2}&&\text{Factor the LHS and simplify the RHS.}&\\[1.25ex]
  \left(x+\frac{b}{a}\right)^2&=\frac{b^2-4ac}{4a^2}&&\text{Take the square root of both sides.}&\\[1.25ex]
  x+\frac{b}{a}&=\pm\frac{\sqrt{b^2-4ac}}{2a}&&\text{Solve for $x$.}&\\[1.25ex]
  x&=\frac{-b\pm\sqrt{b^2-4ac}}{2a}&&\text{\textbf{Quadratic Formula}.}&
\end{align*}
\end{document}

enter image description here

答案2

包裹witharrows提供了一个新的环境WithArrows,类似于align可以使用命令\Arrow在从一行到另一行的箭头旁边打印一些文本。

以下是 OP 示例可能得出的结果:

enter image description here

\documentclass[letterpaper]{article}
\usepackage{fullpage}
\usepackage{amsmath,amssymb,amsthm,enumitem}
\usepackage[dvipsnames]{xcolor}
\usepackage{tikz}
\usetikzlibrary{calc, arrows.meta, bending, decorations.pathreplacing}

\usepackage{witharrows}
\newcommand{\red}[1]{%
{\color{OrangeRed}#1}}

\begin{document}
Let us show that by completing the square, we can achieve this.
\[        \begin{WithArrows}
        f(x)&=ax^2+bx+c \Arrow{Factor $a$ from $ax^2+bx$. Do you know why?}\\
            &=a\left(x^2+\frac{b}{a}x\right)+c \Arrow[tikz=OrangeRed]{Complete the square by adding $\frac{b^2}{4a^2}$.} \\
            &=a\left(x^2+\frac{b}{a}x+\red{\frac{b^2}{4a^2}} \right)+c\red{-a\left(\frac{b^2}{4a^2}\right)}\Arrow{Factor and simplify.}\\
            &=a\left(x+\frac{b}{2a}\right)^2+c-\frac{b^2}{4a}\\
            &=a\left(x+\frac{b}{2a}\right)^2+\frac{4ac-b^2}{4a}\\
            &=a(x-h)^2+k
        \end{WithArrows}
\] \end{document}

enter image description here

\documentclass[letterpaper]{article}
\usepackage{fullpage}
\usepackage{amsmath,amssymb,amsthm,enumitem}
\usepackage[dvipsnames]{xcolor}
\newcommand{\red}[1]{%
{\color{OrangeRed}#1}}

\usepackage{tikz}
\usetikzlibrary{calc, arrows.meta, bending, decorations.pathreplacing}

\usepackage{witharrows}

\begin{document}
Let us apply completing the square to the standard form of a quadratic equation, $ax^2+bx+c=0$.

\[\begin{WithArrows}
    ax^2+bx+c&=0 \Arrow{Divide by $a$, the leading coefficient.}\\
    x^2+\frac{b}{a}x+\frac{c}{a}&=0 \Arrow{Transpose the constant term to the RHS.}\\
    x^2+\frac{b}{a}x&=-\frac{c}{a} \Arrow[tikz=OrangeRed]{Add $\left(\frac{1}{2}\left(\frac{b}{a}\right)\right)^2$ to both sides.}\\
    x^2+\frac{b}{a}x+\frac{b^2}{4a^2}&=-\frac{c}{a}+\frac{b^2}{4a^2} \Arrow{Factor the LHS and simplify the RHS.}\\
    \left(x+\frac{b}{a}\right)^2&=\frac{b^2-4ac}{4a^2} \Arrow{Take the square root of both sides.}\\
    x+\frac{b}{a}&=\pm\frac{\sqrt{b^2-4ac}}{2a} \Arrow{Solve for $x$.}\\
    x&=\frac{-b\pm\sqrt{b^2-4ac}}{2a}
    \end{WithArrows}
\] \end{document}

注意:包文档没有提到它,但我们应该加载TikZcalc, arrows.meta, bending, decorations.pathreplacingtikzlibraries 来使用WithArrows环境。

相关内容