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.

I have this expression: |x-|x-|x-4||| Now, every | sign has the same size, but I'd like to make the outward pairs bigger.

Is it possible to do it automatically, or do I have to define the size of each | sign manually? It doesn't work with $\left| \right|$. In this case I have 3 abs signs. But what if there would be for example 12? Is it possible to do it automatically?

This works fine:

\[
\abs*{\VPhantomL x-\abs*{\VPhantomM x-\abs{x-4}}}
\]

This works fine

But the inline version doesn't:

$\abs*{\VPhantomL x-\abs*{\VPhantomM x-\abs{x-4}}}$

enter image description here

share|improve this question
2  
Have a look at this-similar question How to make math symbols bigger? –  Abhimanyu Arora Jun 8 '12 at 19:35
33  
It is very hard to not post \DoMoreSitups as an answer. –  Scribblemacher Jun 8 '12 at 19:36
6  
I'd try hard not to write such formulas in the first place. :) My (professional) opinion is that things like this live only in high school textbooks, and they shouldn't. –  egreg Jun 8 '12 at 19:49
    
@AbhimanyuArora: I converted your post to a comment because links to other answers or questions do not qualify as new answers. I hope you don't mind. –  Martin Scharrer Jun 8 '12 at 19:54
4  
+1: If only for the pun in the title. –  Thomas Eding Jun 9 '12 at 9:03
show 3 more comments

4 Answers

up vote 24 down vote accepted

TeX also offers a primitive parameter to always make delimiters grow.

\documentclass{article}
\delimitershortfall-1sp
\newcommand\abs[1]{\left|#1\right|}
\begin{document}
\[
\abs{ x-\abs{ x-\abs{x-4}}}
\]
\end{document}

gives the desired output.

enter image description here

\delimitershortfall is meant to measure how much larger the content is allowed to get before the delimiters start growing, but by setting it to a negative value delimiters always grow.

share|improve this answer
2  
Wow!! Never heard of this before!! There was a question here about parenthesis automatically increasing the more nesting there was -- perhaps this would be applicable there. I think I would add the \delimitershortfall-1sp as part of the \abs macro so that the effect of this localized. –  Peter Grill Jun 9 '12 at 5:42
    
@PeterGrill Of course, modify as appropriate. Though if part of the \abs macro, still other delimiters inside the \abs would be affected, so it must be explicitly reset before the #1. In my documents, I like all delimiters to grow ;-) –  Stephan Lehmke Jun 9 '12 at 5:47
1  
@StephanLehmke OH THANKS! It's the best solution! I'll use this with braces too! –  balping Jun 9 '12 at 16:11
add comment

As egreg commented, for this specific case you could also use the optional parameter to the commands declared with DeclarePairedDelimiter and specify the size:

 \abs[\Big]{x-\abs[\big]{x-\abs{x-4}}}

enter image description here

Note:

  • The \left|, \right| pair only resize when there is content in between that has different vertical height. In your case, the content all had the same vertical size and hence no resizing took place.

As an alternate, which might be useful in other cases (but does require more work), you could insert a \vphantom{<content with larger vertical size>}.

Here is a solution that inserts a different \vphatom{} between the pairs of \abs to yield:

Notes:

  • As declared below with DeclarePairedDelimiter, you need to use \abs*{} if you want the delimiter resized based on the vertical size of the content.
  • You can tweak the content of the \VPhamtomL (large), and \VPhantomM (medium), to control the size of the delimiter.

Code:

\documentclass{article}
\usepackage{mathtools}
\DeclarePairedDelimiter\abs{\lvert}{\rvert}%
\begin{document}
You can use the optional paramater to \verb|\abs|:
\[
\abs[\Big]{x-\abs[\big]{x-\abs{x-4}}}
\]

With inline math $\abs[\Big]{x-\abs[\big]{x-\abs{x-4}}}$.

%------------------
\newcommand{\VPhantomL}{\vphantom{x^{2^2}}}%
\newcommand{\VPhantomM}{\vphantom{x^{2}}}%
%
or you can insert a \verb|\vphantom{}|
\[
\abs*{\VPhantomL x-\abs*{\VPhantomM x-\abs{x-4}}}
\]

With inline math $\abs*{\VPhantomL x-\abs*{\VPhantomM x-\abs{x-4}}}$.
\end{document}
share|improve this answer
    
\abs[\Big]{x-\abs[\big]{x-\abs{x-4}}} –  egreg Jun 8 '12 at 19:37
    
Thanks! This works! My only problem is that it works only with [ ] and doesn't work with $ $. Can I fix it? –  balping Jun 8 '12 at 19:47
    
@balping: Both version seem to work fine in inline math -- see updated MWE. If it does not work for you, please edit the question and provide a MWE that illustrates the problem. –  Peter Grill Jun 8 '12 at 20:10
    
@PeterGrill I edited the question –  balping Jun 8 '12 at 20:34
    
@balping: What you posted is a code snippet, and while code snippets are useful in explanations, it is always best to compose a fully compilable MWE that illustrates the problem including the \documentclass and the appropriate packages. Does it work for you if you compile the MWE I provided? Plus have a look at the updated solution that provides a simpler version for this specific equation. –  Peter Grill Jun 8 '12 at 20:51
add comment

You can use nath for automatic scaling of delimiters, but keep in mind that it is incompatible with amsmath (although it does provide its own version of multiline display math environments)

\documentclass[border=3pt]{standalone}
\usepackage{nath}
\delimgrowth=1
\def\abs#1{\lvert#1\rvert} 

\begin{document}
\begin{equation*}
\abs{x \abs{x - \abs{x-4}}}
\end{equation*}
\end{document}

enter image description here

share|improve this answer
add comment

The low-TeX (pun obviously irresistible) solution:

\documentclass{article}
\begin{document}
$\Bigl| x - \bigl| x - | x-4 | \bigr| \Bigr|$
\end{document}

enter image description here

share|improve this answer
    
To whoever down-voted this answer: would you be so kind as to explain your reason for doing so? Did the pun offend you? After all, I'm pretty sure that the code itself is correct -- especially as its output is pretty much identical to that of some of the other answers. –  Mico Jun 10 '12 at 21:05
    
I didn't downvote, but I guess it's related to the boldface "automatically" in the question. –  Hendrik Vogt Jun 11 '12 at 5:49
    
@HendrikVogt: Thanks for this interesting observation. Well, the bold-facing of one instance of the word "automatically" and the addition of the second instance were applied in an edit that occurred only after I posted my answer. I wonder if the other answer who apparently missed this qualifier also got downvoted... –  Mico Jun 11 '12 at 7:33
    
Ah, yes! One should always check the revisions of the question before downvoting. –  Hendrik Vogt Jun 11 '12 at 7:34
add comment

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.