91

I need to write norm of sum, but the sum symbol is larger than tho norm symbol (||) and it doesn't look good. Is there any symbol for norm which will adjust its size?

\documentclass[12pt,a4paper]{article} 
   \begin{document}  
    \begin{equation}
     ||\left(\sum_{n=1}^N \bf P_{\rm n}\rm\right) ||^2 = \left(\sum_n \frac{E_n}{c}\right)^2 - \left(\sum_n \bf p_{\rm n}\rm \right)^2   
    \end{equation}
   \end{document}  
egreg
  • 1,121,712
Suzie
  • 1,289
  • 13
    Please, use \mathbf{P}_{n} and don't use \rm or \bf any more: they have been obsolete for more than ten years in LaTeX. – egreg Apr 06 '13 at 10:22

2 Answers2

130

Either of the following methods should work:

  • You could load the amsmath package and define a \norm macro as follows:

    \newcommand{\norm}[1]{\left\lVert#1\right\rVert}
    

    and then write

    \norm{ \biggl(\sum_{n=1}^N \mathbf{P}_{n}\biggr) }
    

    in the equation of interest. Note that the round parentheses will be too big if you write \left( and \right); I recommend you write \biggl( and \biggr) instead.

    Your example code may therefore be written as

    \documentclass[12pt,a4paper]{article} 
    \usepackage{amsmath}
    \newcommand\norm[1]{\left\lVert#1\right\rVert}
    \begin{document}  
      \begin{equation}
        \norm{ \biggl(\sum_{n=1}^N \mathbf{P}_{n}\biggr) }^2 = 
               \biggl(\sum_n \frac{E_n}{c}\biggr)^2 - 
               \biggl(\sum_n \mathbf{p}_{n} \biggr)^2   
      \end{equation}
    \end{document} 
    

enter image description here

  • Some might say that the resulting norm "fences" in the example above are a bit too large and thus threaten to dominate visually the rest of the math stuff. (This happens, of course, because the macro uses \left and \right directives to size the fences.) To fix this issue, you could load the mathtools package and insert the following instruction in the preamble:

    \DeclarePairedDelimiterX{\norm}[1]{\lVert}{\rVert}{#1}
    

    and use the \norm macro with an explicit size instruction (here: \bigg, i.e., the same size as for the parentheses):

    \documentclass[12pt,a4paper]{article} 
    \usepackage{mathtools}
    \DeclarePairedDelimiterX{\norm}[1]{\lVert}{\rVert}{#1}
    \begin{document} 
      \begin{equation}
        \norm[\bigg]{\biggl(\sum_{n=1}^N \mathbf{P}_{n}\biggr) }^2 = 
                     \biggl(\sum_n \frac{E_n}{c}\biggr)^2 - 
                     \biggl(\sum_n \mathbf{p}_{n} \biggr)^2   
      \end{equation}
    \end{document}
    

enter image description here

Mico
  • 506,678
  • Is there a reason why \lvert and \rvert should be preferred over \|? – Vincent Nivoliers Apr 06 '13 at 10:21
  • 5
  • 3
    @VincentNivoliers - Note that \Vert is equivalent to \|. The l and r prefixes inform TeX that the commands \lVert and \rVert should be given math codes mathopen and mathclose, respectively. (TeX has no way of knowing how to modify the default math code of \Vert.) – Mico Apr 06 '13 at 10:44
  • 2
    Any reason why \norm is not pre-defined in amsmath or some other package? It is a quite common operation. – juliohm Jan 23 '19 at 14:49
  • @juliohm - Questions about why some feature may be present or absent from any particular LaTeX package should be addressed to the package's maintainer(s). – Mico Mar 08 '19 at 10:57
  • This does not work for me, produces product signs... – PascalIv Feb 19 '22 at 10:42
  • @PascalIv - I am very confident that the code shown in my answer does not produce product symbols. Now, my mind-reading skills have always been, currently are, and always will be absolutely worthless. Therefore, unless you tell me what you are actually doing, the likelihood that I'll somehow manage to figure out what could be going on in your LaTeX code that could be poducing product symbols is exactly zero. So, do please divulge a bit more information about what you're doing. – Mico Feb 19 '22 at 13:05
  • 1
    @Mico - I am sorry, sometimes Latex frustration before a deadline makes me post a useless comment. I use beamer, have a lot of imports and \lVert, | etc. produces large Pi/product signs. Was hoping someone maybe saw this before and knows which import messes things up. – PascalIv Feb 21 '22 at 09:17
  • 1
    @PascalIv - If I replace \documentclass[12pt,a4paper]{article} with \documentclass{beamer}, the document still doesn't produce product symbols instead of summation symbols. All I can surmise is that one or more of the packages you're loading (I have no idea which one it could be... -- cf. my earlier comment) would appear to be messing with the meaning of \sum. – Mico Feb 21 '22 at 12:05
66

Use \Vert instead of ||. You can prefix \Vert with any brace-sizing-command, like \left, \right, \big, ..

\documentclass[12pt,a4paper]{article} 
\begin{document}  
    \begin{equation}
        \left\Vert\left(\sum_{n=1}^N \bf P_{\rm n}\rm\right) \right\Vert^2 = \left(\sum_n \frac{E_n}{c}\right)^2 - \left(\sum_n \bf p_{\rm n}\rm \right)^2   
    \end{equation}
\end{document}  

Screenshot

  • 1
    If you want a more 'polished' look for a special case, just look around and search for absolute value. There are many questions here (like this one) which provide additional information, if you want to know more ;) – Peater de Xel Apr 06 '13 at 10:15
  • 9
    All the \rm commands used are wrong: besides being an obsolete command, the n should be in italics. Also \bf is obsolete, use \mathbf{P} and \mathbf{p}. – egreg Apr 06 '13 at 10:16
  • @egreg: Suzie wrote the n in E_n in italics, so I think it was a choice to typeset the n in P_n in an upright shape. – Peater de Xel Apr 06 '13 at 10:18
  • 2
    @ralfix According to mathematical conventions, an italic and an upright "n" don't necessarily denote the same object. My feeling is that \rm has been used in order to countermand \bf, but it's wrong to begin with. – egreg Apr 06 '13 at 10:20
  • @egreg Thank you, the \mathbf{} is really great. Now my work looks much better :) – Suzie Apr 06 '13 at 18:09