写出好看的数学解决方案

写出好看的数学解决方案

我写了很多数学问题的解决方案,最近开始使用 LaTeX。

我有一些要求,我希望所有内容都左对齐,并且我希望能够在方程式环境中进行注释。到目前为止,我还没有找到管理这个问题的最佳方法,请查看下面的代码:

\documentclass[12pt]{article}
\usepackage[fleqn]{amsmath}
\usepackage{enumitem}
\usepackage{amssymb}
\begin{document}

\subsection*{Exercise 1}
Solve the integrals
\begin{enumerate}[label=\alph*)]
\item $\displaystyle \int\limits_0^1 4x \cdot e^{x^2+3} dx$
\begin{flalign*}
u&=x^2+3, $ so that $ \, \frac{du}{dx}=2x &\\
\int & 4x\cdot e^{u}\, \frac{du}{2x} =  2\int e^u \, du = 2e^{x^2+3}+C &\\
\intertext{We now evaluate the limits}
\int\limits_0^1 & 4x\cdot e^{x^2+3} \, dx = 2\left[ e^{x^2+3} \right]\limits_0^1 = 2e^4-2e^3 &
\end{flalign*}
\item $\displaystyle \int \frac{x-6}{x^2-4}  \, dx \\$
\begin{flalign*}
\intertext{We use the method of partial fractions}
&\frac{x-6}{x^2-4} = \frac{A}{x+2}+\frac{B}{x-2}&\\
&(x-6)  = A\cdot(x-2) + B\cdot(x+2) &\\
&\intertext{Which gives $A=2$ and $B=-1$, so that}
&\int \frac{x-6}{x^2-4}\, dx = \int \frac{2}{x+2} + \frac{-1}{x-2}\, dx = 2ln|x+2|-ln|x-2|+C &
\end{enumerate}
\end{flalign*}
\end{document}

它看起来会像这样:

结果

一定有一种“更干净”的方法来做到这一点,对吗?

答案1

这是我对 MWE 格式的看法。除其他外,它用 \tag 替换了 \item。

商品标签

\documentclass[12pt]{article}
\usepackage[leqno]{amsmath}
\usepackage{enumitem}
\usepackage{amssymb}

\newcommand{\mytext}[1]% #1 = same as intertext
{&\parbox{0.9\textwidth}{\rule{0pt}{.5\baselineskip}\\
\textrm{#1}\\
\rule{0pt}{.5\baselineskip}}&\\}

\newcounter{exercise}
\newcounter{problem}[exercise]
\newcommand{\myitem}{\stepcounter{problem}\tag*{\alph{problem})}}

\begin{document}

\stepcounter{exercise}
\subsection*{Exercise \theexercise}
Solve the integrals
\begin{flalign*}
\myitem&\int_0^1 4x \cdot e^{x^2+3} dx &\\
&u=x^2+3 \quad\textrm{so that}\quad \frac{du}{dx}=2x &\\
&\int 4x\cdot e^{u}\, \frac{du}{2x} =  2\int e^u \, du = 2e^{x^2+3}+C &\\
\mytext{We now evaluate the limits}
&\int_0^1 4x\cdot e^{x^2+3} \, dx = 2\left[ e^{x^2+3} \right]_0^1 = 2e^4-2e^3 &
\end{flalign*}
\begin{flalign*}
\myitem&\int \frac{x-6}{x^2-4}  \, dx &\\
\mytext{We use the method of partial fractions}
&\frac{x-6}{x^2-4} = \frac{A}{x+2}+\frac{B}{x-2} \\
\mytext{But this time the comment just keeps on going and going until it is guaranteed to wrap to the next line.}
&(x-6)  = A\cdot(x-2) + B\cdot(x+2) &\\
\mytext{Which gives $A=2$ and $B=-1$, so that}
&\int \frac{x-6}{x^2-4}\, dx = \int \frac{2}{x+2} + \frac{-1}{x-2}\, dx = 2\ln|x+2|-\ln|x-2|+C &
\end{flalign*}
\end{document}

答案2

简短的介绍

这里有三个解决方案——请看示例。

链接

例子

\documentclass{article}
\usepackage{mathtools} % also loads amsmath
\usepackage{parskip}
\begin{document}

\section{Using \texttt{flalign}}

\begin{flalign}
\text{Proof}    && a &= b &&\\
    && a &= b &&\\
    && a &= b && \text{some comment}\\
    && a &= b &&
\end{flalign}

\begin{flalign*}
\text{Proof}    && a &= b &&\\
    && a &= b &&\\
    && a &= b && \text{some comment}\\
    && a &= b &&
\end{flalign*}

\section{Using \texttt{intertext} (amsmath) or \texttt{shortintertext} (mathtools)}

\begin{align}
A &= \int x^2 \text{d}x\\
\intertext{Notice the upright d -- it's an operator and not a variable.}
A &= \int x^2 \text{d}x\\
\shortintertext{Notice the upright d -- it's an operator and not a variable.}
A &= \int x^2 \text{d}x
\end{align}

\noindent\textbf{Taken from the \texttt{amsmath} documentation (Chapter 3.10):}

The command \texttt{intertext} is used for a short interjection of one or two lines
of text in the middle of a multiple-line display structure (see also the \texttt{text}
command in §6). Its salient feature is preservation of the alignment, which
would not happen if you simply ended the display and then started it up again
afterwards. \texttt{intertext} may only appear right after a \textbackslash\textbackslash or \textbackslash\textbackslash* command.

\noindent\textbf{Taken from the \texttt{mathtools} documentation (Chapter 3.5):}

amsmath provides the command \texttt{intertext} for interrupting a multiline display
while still maintaining the alignment points. However the spacing often seems quite
excessive as seen below [\ldots] Using the command \texttt{shortintertext} alleviates this situation somewhat [\ldots]

\end{document}

输出

在此处输入图片描述

答案3

我发现使用equationequation*align等环境align*有助于使 LaTeX 看起来更简单。例如,使用\qquad{\text{}}在环境中的特定行旁边添加注释有助于将代码从杂乱无章的状态转变为更易于阅读的状态。因此,左对齐将由或处理(用于较长的方程式),或和处理(用于单行),并使用上述或间距修饰符进行注释。alignalignalign*equationequation*\quad\qquad

相关内容