0

EDIT:

@egreg 's method works somewhat. As the other equations in the longer code were too long, the whole second column were flushed to the right by these. As I shortened the equations down, the equal signs came closer and closer to the left.

enter image description here

What do I want?:

I am trying to make multiple alignments in my equations using the align enviroment.

Deeper explanation:

I've searched in the forum and tried to use one method of specifying the second column by using double "&" (&&). Also I've tried just using a single "&" (&) a second time within the same equation. But in both of attempts my second alignment makes all the righthand text to be flushed all the way to the right.

This problem occurs when its inbetween some other equations. But when I try it with the double "&" (&&) in code alone, it works pretty good except that it still will be pretty far to the right.

Why I dont want to split the align enviroment into several enviroments:

I want all the equations before and after to also be aligned with these equations in the first column.

Commands I use in the code:

\DeclareMathOperator{\laplace}{\mathcal{L}} %Laplace symbol

\newcommand\ddfrac[2]{\frac{\displaystyle #1}{\displaystyle #2}} % Makes some quotient more visible

Using extra spacing to clearify where I try to make my second alignment.

Here is the code alone, attempt with a double "&" (&&) to specify second column:

\begin{align}
    u_{in}(t) &= u_{ut} + u(t)\\
    %
    \nonumber
    i(t) &= i_L(t) + i_R(t)
    %
\intertext{Laplace-transformering av ovanstående ekvationer ger:}
    %
    U_{ut}(s) &= \laplace\left\{ u_{ut}(t) \right\}(s)          &&= \frac{1}{Cs}I(s) \label{eq:u_ut}\\
    %
    U(s) &= \laplace\left\{ u(t) \right\}(s) =  L[sI_L(s)-i(0)] &&= sLI_L(s) \label{eq:u}\\
    %
    U(s) &= \laplace\left\{ \widetilde{u}(t) \right\}(s)        &&= RI_R(s) \label{eq:omhs}\\
    %
    U_{in}(s) &= \laplace\left\{ u_{in}(t) \right\}(s)          &&= U_{ut}(s) + U(s) \label{eq:u_in}\\
    %
    I(s) &= \laplace\left\{ i(t) \right\}(s)                    &&= I_L(s) + I_R(s) \label{eq:i}\\
    %
    \intertext{Överföringsfunktionen blir då:}   
    %
    H(s) &= \frac{U_{ut}(s)}{U_{in}(s)}
\end{align}

This gives partly this result: Code alone Here is the full align enviroment, pretty much code but that is why I inserted the example above.

\begin{align}
        \nonumber
        u_{ut}(t) &= \frac{1}{C}\int_0^ti(t)dt\\ 
        %           
        \nonumber
        u(t) &= L\frac{di_L(t)}{dt}\\
        %
    \intertext{Ohm's lag:}
        %
        \nonumber
        u(t) &= \widetilde{u}(t) = i_R(t)R\\
        %
        \nonumber
    \intertext{Kirchoff's lagar:}    
        %
        \nonumber
        u_{in}(t) &= u_{ut} + u(t)\\
        %
        \nonumber
        i(t) &= i_L(t) + i_R(t)
        %
    \intertext{Laplace-transformering av ovanstående ekvationer ger:}
        %
        U_{ut}(s) &= \laplace\left\{ u_{ut}(t) \right\}(s)          &&= \frac{1}{Cs}I(s) \label{eq:u_ut}\\
        %
        U(s) &= \laplace\left\{ u(t) \right\}(s) =  L[sI_L(s)-i(0)] &&= sLI_L(s) \label{eq:u}\\
        %
        U(s) &= \laplace\left\{ \widetilde{u}(t) \right\}(s)        &&= RI_R(s) \label{eq:omhs}\\
        %
        U_{in}(s) &= \laplace\left\{ u_{in}(t) \right\}(s)          &&= U_{ut}(s) + U(s) \label{eq:u_in}\\
        %
        I(s) &= \laplace\left\{ i(t) \right\}(s)                    &&= I_L(s) + I_R(s) \label{eq:i}\\
        %
    \intertext{Överföringsfunktionen blir då:}   
        %
        \nonumber
        H(s) &= \frac{U_{ut}(s)}{U_{in}(s)} = 
        %
    \intertext{Insättning av ekvationerna \ref{eq:u_ut} \& \ref{eq:u} ger:}
        %
        &=\frac{I(s)}{sC\left(\frac{1}{sC}I(s)+U(s)\right)} = \ddfrac{I(s)}{I(s)+sCU(s)} \label{eq:h1}\\
        %
    \intertext{Insättning av ekvation \ref{eq:i} i ekvation \ref{eq:omhs} ger:}
        %
        \nonumber
        U(s) &= RI_R(s) = R(I(s)-I_L(s)) =
        %
    \intertext{Insättning av ekvation \ref{eq:u} ger:}
        %
        \nonumber       
        &= R\left(I(s)-\frac{U(s)}{sL}\right)\\
        %
    \intertext{Alltså:} 
        %
        \nonumber
        U(s) &=     R\left(I(s)-\frac{U(s)}{sL}\right)
        %
    \intertext{Bryt ut U(s):}
        %
        U(s) &= \ddfrac{R}{\left(1+\frac{R}{sL}\right)}I(s) = \frac{sRL}{R+sL}I(s) \label{eq:u2}
        %
    \intertext{Insättning av ekvation \ref{eq:u2} i ekvation \ref{eq:h1} ger:}
        %
        \nonumber
        H(s) &= \ddfrac{I(s)}{I(s)+\frac{s^2RLC}{R+sL}I(s)} = \ddfrac{1}{1+\frac{s^2RLC}{R+sL}} = \ddfrac{R+sL}{R+sL+s^2RLC}\\
        %
    \intertext{Alltså:}
        %
        H(s) &= \ddfrac{R+sL}{R+sL+s^2RLC} \label{eq:h_laplace}
    \end{align}

Which gives me this (the interesting part): enter image description here

4

Change \begin{align} into \begin{alignat}{2} and \end{align} into \end{alignat}.

I've also added split around the first two equations, so it's clearer that the number refers to both of them.

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[swedish]{babel}
\usepackage{amsmath}

\DeclareMathOperator{\laplace}{\mathcal{L}} %Laplace symbol

\begin{document}

\begin{alignat}{2}
  \begin{split}
  u_{\mathrm{in}}(t) &= u_{\mathrm{ut}} + u(t)\\
  %
  i(t) &= i_L(t) + i_R(t)
  \end{split}
  %
\intertext{Laplace-transformering av ovanstående ekvationer ger:}
  %
  U_{\mathrm{ut}}(s) &= \laplace\{ u_{\mathrm{ut}}(t) \}(s) &&= \frac{1}{Cs}I(s) \label{eq:u_ut}\\
  %
  U(s) &= \laplace\{ u(t) \}(s) =  L[sI_L(s)-i(0)]          &&= sLI_L(s) \label{eq:u}\\
  %
  U(s) &= \laplace\{ \widetilde{u}(t) \}(s)                 &&= RI_R(s) \label{eq:omhs}\\
  %
  U_{\mathrm{in}}(s) &= \laplace\{ u_{\mathrm{in}}(t) \}(s) &&= U_{\mathrm{ut}}(s) + U(s) \label{eq:u_in}\\
  %
  I(s) &= \laplace\{ i(t) \}(s)                             &&= I_L(s) + I_R(s) \label{eq:i}\\
  %
  \intertext{Överföringsfunktionen blir då:}   
  %
  H(s) &= \frac{U_{\mathrm{ut}}(s)}{U_{\mathrm{in}}(s)}
\end{alignat}

\end{document}

enter image description here

For the longer display you can do the same, but you have to “hide” the longer equations (and they could go beyond the margin without you knowing it.

(I fixed the most common errors, such as useless \left and \right, non upright subscripts and unnecessary big fractions).

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[swedish]{babel}
\usepackage{amsmath,mathtools}

\DeclareMathOperator{\laplace}{\mathcal{L}} %Laplace symbol

\begin{document}
\begin{alignat}{2}
  \nonumber
  u_{\mathrm{ut}}(t) &= \frac{1}{C}\int_0^ti(t)dt\\ 
  %           
  \nonumber
  u(t) &= L\frac{di_L(t)}{dt}\\
  %
\intertext{Ohm's lag:}
  %
  \nonumber
  u(t) &= \widetilde{u}(t) = i_R(t)R\\
  %
  \nonumber
\intertext{Kirchoff's lagar:}    
  %
  \nonumber
  u_{\mathrm{in}}(t) &= u_{\mathrm{ut}} + u(t)\\
  %
  \nonumber
  i(t) &= i_L(t) + i_R(t)
  %
\intertext{Laplace-transformering av ovanstående ekvationer ger:}
  %
  U_{\mathrm{ut}}(s) &= \laplace\{ u_{\mathrm{ut}}(t) \}(s)          &&= \frac{1}{Cs}I(s) \label{eq:u_ut}\\
  %
  U(s) &= \laplace\{ u(t) \}(s) =  L[sI_L(s)-i(0)] &&= sLI_L(s) \label{eq:u}\\
  %
  U(s) &= \laplace\{ \widetilde{u}(t) \}(s)        &&= RI_R(s) \label{eq:omhs}\\
  %
  U_{\mathrm{in}}(s) &= \laplace\{ u_{\mathrm{in}}(t) \}(s)          &&= U_{\mathrm{ut}}(s) + U(s) \label{eq:u_in}\\
  %
  I(s) &= \laplace\{ i(t) \}(s)                    &&= I_L(s) + I_R(s) \label{eq:i}\\
  %
\intertext{Överföringsfunktionen blir då:}   
  %
  \nonumber
  H(s) &= \frac{U_{\mathrm{ut}}(s)}{U_{\mathrm{in}}(s)} = 
  %
\intertext{Insättning av ekvationerna \ref{eq:u_ut} \& \ref{eq:u} ger:}
  %
       &=\mathrlap{\frac{I(s)}{sC(\frac{1}{sC}I(s)+U(s))} = \frac{I(s)}{I(s)+sCU(s)}} \label{eq:h1}\\
  %
\intertext{Insättning av ekvation \ref{eq:i} i ekvation \ref{eq:omhs} ger:}
  %
  \nonumber
  U(s) &= RI_R(s) = R(I(s)-I_L(s)) =
  %
\intertext{Insättning av ekvation \ref{eq:u} ger:}
  %
  \nonumber       
       &= R\left(I(s)-\frac{U(s)}{sL}\right)\\
  %
\intertext{Alltså:} 
  %
  \nonumber
  U(s) &=     R\left(I(s)-\frac{U(s)}{sL}\right)
  %
\intertext{Bryt ut $U(s)$:}
  %
  U(s) &= \frac{R}{(1+\frac{R}{sL})}I(s) = \frac{sRL}{R+sL}I(s) \label{eq:u2}
  %
\intertext{Insättning av ekvation \ref{eq:u2} i ekvation \ref{eq:h1} ger:}
  %
  \nonumber
  H(s) &= \mathrlap{\frac{I(s)}{I(s)+\dfrac{s^2RLC}{R+sL}I(s)}
        = \frac{1}{1+\dfrac{s^2RLC}{R+sL}}
        = \frac{R+sL}{R+sL+s^2RLC}} \\
  %
\intertext{Alltså:}
  %
  H(s) &= \frac{R+sL}{R+sL+s^2RLC} \label{eq:h_laplace}
\end{alignat}

\end{document}

The result is, sorry to say, poor. I'd rather use alignment only when it's really necessary. There's no reason for the equals signs in the first two equations to be aligned with the one in the last equation on the next page.

By the way, the first two equations can better be on the same line, with a generous (\qquad) separation, as well as Kirchhoff's laws (there are two h's in the name, as far as I know).

Here's the version I propose:

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[swedish]{babel}
\usepackage{amsmath,mathtools}

\DeclareMathOperator{\laplace}{\mathcal{L}} %Laplace symbol

\begin{document}
\begin{equation*}
  u_{\mathrm{ut}}(t) = \frac{1}{C}\int_0^ti(t)dt
  \qquad
  u(t) = L\frac{di_L(t)}{dt}
\end{equation*}
Ohm's lag:
\begin{equation*}
  u(t) = \widetilde{u}(t) = i_R(t)R
\end{equation*}
Kirchhoff's lagar:
\begin{equation*}
  u_{\mathrm{in}}(t) = u_{\mathrm{ut}} + u(t)
  \qquad
  i(t) = i_L(t) + i_R(t)
\end{equation*}
Laplace-transformering av ovanstående ekvationer ger:
\begin{alignat}{2}
  U_{\mathrm{ut}}(s) &= \laplace\{ u_{\mathrm{ut}}(t) \}(s)
    &&= \frac{1}{Cs}I(s) \label{eq:u_ut}\\
  U(s) &= \laplace\{ u(t) \}(s) =  L[sI_L(s)-i(0)]
    &&= sLI_L(s) \label{eq:u}\\
  U(s) &= \laplace\{ \widetilde{u}(t) \}(s)
    &&= RI_R(s) \label{eq:omhs}\\
  U_{\mathrm{in}}(s) &= \laplace\{ u_{\mathrm{in}}(t) \}(s)
    &&= U_{\mathrm{ut}}(s) + U(s) \label{eq:u_in}\\
  I(s) &= \laplace\{ i(t) \}(s)
    &&= I_L(s) + I_R(s) \label{eq:i}
\end{alignat}
Överföringsfunktionen blir då:
\begin{align}
  \nonumber
  H(s) &= \frac{U_{\mathrm{ut}}(s)}{U_{\mathrm{in}}(s)} = 
\intertext{Insättning av ekvationerna \ref{eq:u_ut} \& \ref{eq:u} ger:}
       &=\frac{I(s)}{sC(\frac{1}{sC}I(s)+U(s))} = \frac{I(s)}{I(s)+sCU(s)} \label{eq:h1}
\end{align}
Insättning av ekvation \ref{eq:i} i ekvation \ref{eq:omhs} ger:
\begin{align*}
  U(s) &= RI_R(s) = R(I(s)-I_L(s)) =
\intertext{Insättning av ekvation \ref{eq:u} ger:}
       &= R\left(I(s)-\frac{U(s)}{sL}\right)
\end{align*}
Alltså:
\begin{equation*}
  U(s) = R\left(I(s)-\frac{U(s)}{sL}\right)
\end{equation*}
Bryt ut $U(s)$:
\begin{equation}
  U(s) = \frac{R}{(1+\frac{R}{sL})}I(s) = \frac{sRL}{R+sL}I(s) \label{eq:u2}
\end{equation}
Insättning av ekvation \ref{eq:u2} i ekvation \ref{eq:h1} ger:
\begin{equation*}
  H(s) = \frac{I(s)}{I(s)+\dfrac{s^2RLC}{R+sL}I(s)}
       = \frac{1}{1+\dfrac{s^2RLC}{R+sL}}
       = \frac{R+sL}{R+sL+s^2RLC}
\end{equation*}
Alltså:
\begin{equation}
  H(s) = \frac{R+sL}{R+sL+s^2RLC} \label{eq:h_laplace}
\end{equation}

\end{document}

enter image description here

  • When I try this method within the longer code, I still get this result with it being very far to the right: imgur.com/jv0r0sb – Robin Hellmers Oct 25 '16 at 21:13
  • @RobinHellmers did you remember to change the env while keeping the same number of &? – daleif Oct 25 '16 at 21:23
  • @daleif Yes I only changed the \begin{align} to \begin{alignat}{2} and the \end{align} to \end{alignat}. I kept the double &. – Robin Hellmers Oct 25 '16 at 21:28
  • 1
    @RobinHellmers and there is three & per line? Then please add that code to your question for us to look at – daleif Oct 25 '16 at 21:30
  • 2
    @RobinHellmers You have a very long equation after “Insättning av ekvation 7 i ekvation 6 ger:” I don't think it's a very good idea to keep alignments so long; I see no reason for it. – egreg Oct 25 '16 at 21:31

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.