2

I am writing an assignment and I have a long algorithm that takes up almost a whole page. I would really like this to be shoved to the side so I can write besides it. For the algorithm to look correct I have used align*, and i tried \hfill and the tabular environment, but I can't figure it out. Help? If it is in a box or not doesn't necessarily matter.

\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

Appreciate any help.

  • 1
    First of all I do not quite understand what it is you want, and secondly that sniplet will not compile. – daleif Nov 5 '14 at 9:24
5

You should put all your math inside of a wrapfigure. Like this, the text will just wrap around it.

% 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}

enter image description here

| improve this answer | |
  • @Andreas Glad I could help. If it is the desired answer, you might want to click the check mark on the left in order to close this issue. Thank you! – LaRiFaRi Nov 5 '14 at 11:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.