# Writing an equation with the units positioned off right

Okay so I have a have a lot of equations in the document I am writing and I am trying to display the units of an equation off to the right. I was wondering how I can achieve this? Right now, all I can do is write the equation with the units attached at the end. Here is my code:

\usepackage{amsmath, siunitx}
\begin{document}

$${ I_0 \equiv \frac{4E_p}{{\tau}{w_{0}^{2}}\pi\sqrt{2\pi}} [\si{\watt\per\meter\squared}] } \label{eq:PeakIntensity}$$

Where

$${ E_p \equiv \frac{P}{R} [\si{\joule}] } \label{eq:PulseEnergy}$$

\end{document}


Thanks for any and all help!

edit: One more thing while I have this posted! I'm sure this is simple, but how do I also display the equation number on the far right of the page so I can reference equations later? Thanks!

-

Adding the information directly into \tag as in another answer is a bad idea, since the added material will also appear in cross-references, which clearly is undesired.

Here's another option producing the right result for cross-references;

\documentclass{article}
\usepackage{amsmath}
\usepackage{siunitx}
\sisetup{detect-all}

\makeatletter
\renewcommand\tagform@[1]{%
}
\makeatother

\begin{document}

As we see in Equations~\eqref{eq:PeakIntensity} and~\eqref{eq:PulseEnergy}...

$$\label{eq:PeakIntensity} I_0 \equiv \frac{4E_p}{{\tau}{w_{0}^{2}}\pi\sqrt{2\pi}} \tagaddtext{[\si{\watt\per\meter\squared}]}$$
Where
$$\label{eq:PulseEnergy} E_p \equiv \frac{P}{R} \tagaddtext{[\si{\joule}]}$$

\end{document}


The \tagaddtext macro is a variation of Werner's definition in his answer to Numbered equations with additional text part 2.

-
A long equation will overlap the unit. – egreg Mar 20 '14 at 23:11
Thank you, this is what I want. I went to Werner's answer to try and see if I could interpret the code sequence, ie what the purpose and function of the code is doing. Any chance of a brief explanation? If not that's okay, I'll just have to keep this written down for the future. Thanks again! – chris Mar 20 '14 at 23:14
@chris You're welcome! The code simply redefines an internal command (\tagform@) from amsmath so the text can be added without colateral effects. I'll add some explanations later. – Gonzalo Medina Mar 20 '14 at 23:20
@Gonzalo Sounds good! I'll keep an eye out ;). – chris Mar 21 '14 at 0:05

A solution with flalign and a variant, that use the original counters. I use a macro called \unit (resp. \varunit) that place the unit at a small distance from the equation number. The difference is that the equations are centred with respect the space that remains between the left margin and the unit, while for the variant it is centred with respect to the leftmargin and the em space before the equation number. It's only a matter of aesthetic choice.

    \documentclass[11pt, a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{lmodern, amssymb, amsfonts}
\usepackage{mathtools}
\usepackage{siunitx}
\begin{document}

\begin{flalign}
&  &  I_0 & \equiv \frac{4E_p}{{\tau}{w_{0}^{2}}\pi\sqrt{2\pi}} \unit{\watt\per\meter\squared}%
\label{eq:PeakIntensity}
\shortintertext{ Where}
&  &    E_p  & \equiv \frac{P}{R}     \unit{\joule}
\label{eq:PulseEnergy}
\end{flalign}
\bigskip

\textbf{Variant:}
\begin{flalign}
&  &  I_0 & \equiv \frac{4E_p}{{\tau}{w_{0}^{2}}\pi\sqrt{2\pi}}   \varunit{\watt\per\meter\squared}
\label{eq:PeakIntensity}
\shortintertext{ Where}
&  &    E_p  & \equiv \frac{P}{R}       \varunit{\joule}
\label{eq:PulseEnergy}
\end{flalign}
\end{document}


If you do not want to align the \equiv signs, you just have to use 2 flalign environments.

-

My suggestion is simply not typesetting the unit, because units are not invariants, while the formula is. So you have E_p=P/R (maybe with some constant around) even if your energy was measured in ergs or other units. That I_0 is in watt per squared meter is already obvious from the what's said when the quantity was being defined. Note also that square brackets are used to denote physical dimensions, while a joule is a physical quantity.

This said, you have some choices:

1. no unit
2. the unit typeset at a fixed distance from the equation number (with flalign)
3. the unit typeset at a fixed distance from the equation, participating to the centering
4. the unit typeset at a fixed distance from the equation, not participating to the centering

In the example, I don't show the first (recommended) choice. Note that the last one may cause overlaps if the formula is long.

\documentclass{article}
\usepackage{mathtools, siunitx}
\begin{document}

Some text above
\begin{flalign}
&&&I_0 \equiv \frac{4E_p}{{\tau}{w_{0}^{2}}\pi\sqrt{2\pi}},
&&(\si{\watt\per\meter\squared})
\label{eq:PeakIntensity}
\end{flalign}
where
\begin{flalign}
&&&E_p \equiv \frac{P}{R}.
&&(\si{\joule})
\label{eq:PulseEnergy}
\end{flalign}

Some text above
$$I_0 \equiv \frac{4E_p}{{\tau}{w_{0}^{2}}\pi\sqrt{2\pi}}, \qquad (\si{\watt\per\meter\squared}) \label{eq:PeakIntensity2}$$
where
$$E_p \equiv \frac{P}{R}. \qquad (\si{\joule}) \label{eq:PulseEnergy2}$$

Some text above
$$I_0 \equiv \frac{4E_p}{{\tau}{w_{0}^{2}}\pi\sqrt{2\pi}}, \mathrlap{\qquad (\si{\watt\per\meter\squared})} \label{eq:PeakIntensity3}$$
where
$$E_p \equiv \frac{P}{R}. \mathrlap{\qquad (\si{\joule})} \label{eq:PulseEnergy3}$$

\end{document}


Note also that mathtools is used for \mathrlap; it automatically loads amsmath.

A modification of Gonzalo's answer, that won't have the defect that the equation can overlap the unit.

\documentclass{article}
\usepackage{amsmath, siunitx}
\sisetup{detect-all}

\makeatletter
%%% redefine \eqref to be like the original
\renewcommand{\eqref}[1]{\textup{\eqreftagform@{\ref{#1}}}}
\let\eqreftagform@\tagform@
%%% redefine \tagform@
\def\tagform@#1{%
\maketag@@@{%
(\ignorespaces#1\unskip\@@italiccorr)%
}%
}
\newif\if@unit
\def\equnit#1{%
\gdef\thiseq@unit{#1}%
\global\@unittrue
}
\makeatother

\begin{document}

$$I_0 \equiv \frac{4E_p}{{\tau}{w_{0}^{2}}\pi\sqrt{2\pi}}, \equnit{\si{\watt\per\meter\squared}} \label{eq:PeakIntensity}$$
where
$$E_p \equiv \frac{P}{R}. \equnit{\si{\joule}} \label{eq:PulseEnergy}$$
Let's see with \texttt{align}:
\begin{align}
I_0 &\equiv \frac{4E_p}{{\tau}{w_{0}^{2}}\pi\sqrt{2\pi}},
\equnit{\si{\watt\per\meter\squared}}
\label{eq:PeakIntensity2}\\
E_p &\equiv \frac{P}{R}.
\equnit{\si{\joule}}
\label{eq:PulseEnergy2}
\end{align}
An equation without unit:
$$1=1$$
A long equation with unit:
$$aaaaaaaaaaaaaaaaaaaaaaa=bbbbbbbbbbbbbbbbbbbb+ccccccccccccccc \equnit{\si{\joule}}$$
A longer equation with unit:
$$aaaaaaaaaaaaaaaaaaaaaaa=bbbbbbbbbbbbbbbbbbbb+cccccccccccc+ddddddd \equnit{\si{\joule}}$$
The references: \eqref{eq:PeakIntensity} and \eqref{eq:PulseEnergy};
\eqref{eq:PeakIntensity2} and \eqref{eq:PulseEnergy2}.
\end{document}


-

In relation to the last two examples, the units should be shown in square brackets, not parenthesis. This is part of the conventions used in the SI and it was discussed in other articles like Unit column in table with square brackets and siunitx.

-
Though this is a good point, it's probably better made as a comment, rather than an answer. – Arun Debray Apr 27 at 21:27