将数学序列与文本对齐

将数学序列与文本对齐

我正在写作业,其中有一个很长的算法,几乎占据了整整一页。我真的很想把它推到一边,这样我就可以在旁边写字了。为了让算法看起来正确,我使用了 align*,并尝试了 \hfill 和 tabular 环境,但我搞不懂。帮忙?它是否在框中并不重要。

\documentclass[a4paper, 11pt]{article}
\usepackage{amsmath}

\begin{document}
bla bla bal bla bla bla bla bla

\begin{align*}
    \Delta_t=&\,(t_{slutt}-t_{start})/n\\
    t_0=&\,t_{start}\\
    \text{for}\,k& = 0, 1,\dots, n-1\\
    %Posisjon + 1/2
    &x_{k+1/2} = x_k + v_{x, k}\Delta_{t/2}\\
    &y_{k+1/2} = y_k + v_{y, k}\Delta_{t/2}\\
    &z_{k+1/2} = z_k + v_{z, k}\Delta_{t/2}\\
    &r = \sqrt{{x_{k+1/2}^2+y_{k+1/2}^2+z_{k+1/2}^2}}\\
    &a = -\frac{\text{GM}}{r^3}\\
    % Fart +1/2
    &v_{x, k+1/2} = v_{x, k} + (\bar{a}x_{k+1/2})\Delta_{t/2}\\
    &v_{y, k+1/2} = v_{y, k} + (\bar{a}y_{k+1/2})\Delta_{t/2}\\
    &v_{z, k+1/2} = v_{z, k} + (\bar{a}z_{k+1/2})\Delta_{t/2}\\
    \\% Posisjon + 1
    &x_{k+1}=x_k + v_{x, k+1/2}\Delta_t\\
    &y_{k+1}=y_k + v_{y, k+1/2}\Delta_t\\
    &z_{k+1}=z_k + v_{z, k+1/2}\Delta_t\\
    % Fart +1
    &v_{x, k+1}=v_{x, k} + \bar{a}x_{k+1/2}\Delta_t\\
    &v_{y, k+1}=v_{y, k} + \bar{a}y_{k+1/2}\Delta_t\\
    &v_{z, k+1}=v_{z, k} + \bar{a}z_{k+1/2}\Delta_t\\
    \\
    &t_{k+1} =a+(k+1)\Delta_t\\
\end{align*}

bla bla bal bla bla bla bla bla

感谢任何帮助。

答案1

你应该把所有的数学公式放在 里面wrapfigure。这样,文本就会环绕它。

% arara: pdflatex

\documentclass[a4paper, 11pt]{article}
\usepackage{mathtools}
\usepackage{wrapfig}
\usepackage{blindtext}
\newcommand*{\vstrut}{\vphantom{\frac{1}{2}}}

\begin{document}
    \blindtext  
    \begin{wrapfigure}{l}{.5\textwidth}
    \begin{align*}
        \Delta&=\frac{t_\text{slutt}-t_\text{start}}{n}\\
        t_0&=t_\text{start}\\
        \shortintertext{for $k = 0, 1,\dots, n-1$}
        x_{k+\frac{1}{2}} &= x_{k\vstrut} + v_{x, k\vstrut}\,\Delta_\frac{t}{2}\\
        y_{k+\frac{1}{2}} &= y_{k\vstrut} + v_{y, k\vstrut}\,\Delta_\frac{t}{2}\\
        z_{k+\frac{1}{2}} &= z_{k\vstrut} + v_{z, k\vstrut}\,\Delta_\frac{t}{2}\\
        r &= \sqrt{{x_{k+\frac{1}{2}}^2+y_{k+\frac{1}{2}}^2+z_{k+\frac{1}{2}}^2}}\\
        a &= -\frac{\mathrm{GM}}{r^3}\\
        v_{x, k+\frac{1}{2}} &= v_{x, k\vstrut} + \bar{a}x_{k+\frac{1}{2}}\,\Delta_\frac{t}{2}\\
        v_{y, k+\frac{1}{2}} &= v_{y, k\vstrut} + \bar{a}y_{k+\frac{1}{2}}\,\Delta_\frac{t}{2}\\
        v_{z, k+\frac{1}{2}} &= v_{z, k\vstrut} + \bar{a}z_{k+\frac{1}{2}}\,\Delta_\frac{t}{2}\\[.7ex]
        x_{k+1\vstrut}&=x_{k\vstrut} + v_{x, k+\frac{1}{2}}\,\Delta_{t\vstrut}\\
        y_{k+1\vstrut}&=y_{k\vstrut} + v_{y, k+\frac{1}{2}}\,\Delta_{t\vstrut}\\
        z_{k+1\vstrut}&=z_{k\vstrut} + v_{z, k+\frac{1}{2}}\,\Delta_{t\vstrut}\\[.7ex]
        v_{x, k+1\vstrut}&=v_{x, k\vstrut} + \bar{a}x_{k+\frac{1}{2}}\,\Delta_{t\vstrut}\\
        v_{y, k+1\vstrut}&=v_{y, k\vstrut} + \bar{a}y_{k+\frac{1}{2}}\,\Delta_{t\vstrut}\\
        v_{z, k+1\vstrut}&=v_{z, k\vstrut} + \bar{a}z_{k+\frac{1}{2}}\,\Delta_{t\vstrut}\\[.7ex]
        t_{k+1} &= a+(k+1)\,\Delta_t
    \end{align*}
    \end{wrapfigure}    
    \Blindtext
\end{document}

在此处输入图片描述

相关内容