Double underlining an answer while keeping the equations aligned at “=” symbol

I've just recently started using LaTeX for homework and I'm wondering how I can double underline an answer while still keeping the equations aligned at the "=" symbol? I have this piece of code:

  \begin{align}
\frac{f'_N}{f'_K}&=\frac{w}{r}\\
\frac{1+2K}{2N}&=\frac{w}{r}\\
\cancel{2N}\cdot\frac{2K+1}{\cancel{2N}}&=\frac{w}{r}\cdot 2N\\
2K&=\frac{w}{r}\cdot \left. 2N-1 \hspace{1cm}\right|\cdot \frac{1}{2} \\
K&=\frac{w}{r}\cdot N-\frac{1}{2}
\end{align}


I want to be able to double underline the last equation as an answer but also keep all of the equations aligned at the "=" symbol. I've tried

\underline{\underline{K&=\frac{w}{r}\cdot N-\frac{1}{2}}}


however the ampersand symbol seems to conflict with something giving me errors when I try to compile. When I remove the ampersand from the equation I want double underlined it compiles perfectly, but with that last equation not aligned with the others. I've tried searching for answers to this, but I haven't found any solutions as of yet. Does anyone know how to achieve this?

• Welcome to TeX.SX! Please help us to help you and add a minimal working example (MWE) that illustrates your problem. It will be much easier for us to reproduce your situation and find out what the issue is when we see compilable code, starting with \documentclass{...} and ending with \end{document}. – user31729 Mar 11 '15 at 23:09
• The \hspace{1cm} looks weird ;-) – user31729 Mar 11 '15 at 23:12
• \mathrlap{<content without &>}<content with &> – Manuel Mar 11 '15 at 23:16

Here are two ways:

\documentclass{article}

\usepackage{mathtools,cancel}

\newlength{\mylen}
\settowidth{\mylen}{$K$}

\begin{document}

\begin{align}
\frac{f'_N}{f'_K} &= \frac{w}{r} \\
\frac{1+2K}{2N} &= \frac{w}{r} \\
\cancel{2N}\cdot\frac{2K+1}{\cancel{2N}} &= \frac{w}{r}\cdot 2N \\
2K &= \frac{w}{r}\cdot \left. 2N-1 \hspace{1cm}\right|\cdot \frac{1}{2} \\
K &= \frac{w}{r}\cdot N-\frac{1}{2} \\
&\hspace*{-\mylen}\underline{\underline{K = \frac{w}{r}\cdot N-\frac{1}{2}}} \\
&\mathllap{\underline{\underline{K\vphantom{\frac{1}{2}}}}}
\underline{\underline{{}= \frac{w}{r}\cdot N-\frac{1}{2}}}
\end{align}

\end{document}


The first uses a horizontal adjustment based on the width of the content that is to sit on the LHS of the equality. The second duplicates the underline for the LHS but setting it using a left math overlap (provided by mathtools). Vertical height adjustment (via \vphantom) makes sure that the separate \underline{\underline{...}} constructions line up.