Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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}

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

    Where

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

\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!

share|improve this question

3 Answers 3

up vote 9 down vote accepted

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
\providecommand\add@text{}
\newcommand\tagaddtext[1]{%
  \gdef\add@text{#1\gdef\add@text{}}}% 
\renewcommand\tagform@[1]{%
  \maketag@@@{\llap{\add@text\quad}(\ignorespaces#1\unskip\@@italiccorr)}%
}
\makeatother

\begin{document}

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

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

\end{document}

enter image description here

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

share|improve this answer
    
A long equation will overlap the unit. –  egreg Mar 20 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 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 at 23:20
    
@Gonzalo Sounds good! I'll keep an eye out ;). –  chris Mar 21 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} 
    \newcommand*\unit[1]{&  & \si{[#1]}\quad}
    \newcommand*\varunit[1]{& \llap{\si{[#1]}}&\quad}
    \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}

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

share|improve this answer

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
\begin{equation}
  I_0 \equiv \frac{4E_p}{{\tau}{w_{0}^{2}}\pi\sqrt{2\pi}},
  \qquad (\si{\watt\per\meter\squared})
  \label{eq:PeakIntensity2}
\end{equation}
where
\begin{equation}
  E_p \equiv \frac{P}{R}.
  \qquad (\si{\joule})
  \label{eq:PulseEnergy2}
\end{equation} 

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

\end{document}

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

enter image description here


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@@@{%
    \if@unit(\thiseq@unit)\quad\fi\global\@unitfalse
    (\ignorespaces#1\unskip\@@italiccorr)%
  }%
}
\newif\if@unit
\def\equnit#1{%
  \gdef\thiseq@unit{#1}%
  \global\@unittrue
}
\makeatother

\begin{document}

\begin{equation}            
I_0 \equiv \frac{4E_p}{{\tau}{w_{0}^{2}}\pi\sqrt{2\pi}},
\equnit{\si{\watt\per\meter\squared}}
\label{eq:PeakIntensity}
\end{equation}
where
\begin{equation}            
E_p \equiv \frac{P}{R}.
\equnit{\si{\joule}}
\label{eq:PulseEnergy}
\end{equation}
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:
\begin{equation}
1=1
\end{equation}
A long equation with unit:
\begin{equation}
aaaaaaaaaaaaaaaaaaaaaaa=bbbbbbbbbbbbbbbbbbbb+ccccccccccccccc
\equnit{\si{\joule}}
\end{equation}
A longer equation with unit:
\begin{equation}
aaaaaaaaaaaaaaaaaaaaaaa=bbbbbbbbbbbbbbbbbbbb+cccccccccccc+ddddddd
\equnit{\si{\joule}}
\end{equation}
The references: \eqref{eq:PeakIntensity} and \eqref{eq:PulseEnergy};
\eqref{eq:PeakIntensity2} and \eqref{eq:PulseEnergy2}.
\end{document}

enter image description here

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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