5
\begin{align} 
\int \arctan x \, dx & = \overbrace{\int u\,dx = xu - \int x\,du}^
    \text{integration by parts} \\[10pt] & \phantom{{} = \int u\,dx} 
= x\arctan x - \int x\left( \frac{dx}{1+x^2} \right) 
\end{align}

I want the overbrace to be right where it is, identifying the basic integration-by-parts identity, and I want the "=" on the next line to be aligned with the one in that identity, and I want to continue this for several more lines with the same alignment. Is there an elegant and efficient way to do this, as opposed to just repeating the phantom on every line?

  • Except for the \,, this looks good as is. Do you have a specific problem with it. Oh, and perhaps \mathrm{d}x, but that is a matter of taste. For future reference, 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 so that those trying to help don't have to recreate it. – Peter Grill Jul 15 '16 at 20:12
  • @PeterGrill : The final result looks good, but the method of coding is cumbersome and inelegant. I'm trying to do some alignment so it would be nice if just somehow using some alignment tabs could accomplish that. – Michael Hardy Jul 15 '16 at 20:15
  • You don't like \int f(x),dx? Is \int f(x)~dx what you prefer? – Michael Hardy Jul 15 '16 at 20:16
  • 1
    Since your alignment point is within another macro, I think the use of a \phantom (perhaps \hphantom would be better as you are only looking for horizontal alignment) is an acceptable approach. Another option is to use \tikzmark and draw the brace separately -- then you do not have to use the hphantom, but some would consider that overkill. Instead of adding \, see if x \mathrm{d}x works for you. – Peter Grill Jul 15 '16 at 20:17
  • Maybe I should add that I want the alignment to continue for several more lines after that, so adding the same \phantom every time seems inelegant. – Michael Hardy Jul 15 '16 at 20:21
  • 1
    I understand the arguments for \mathrm{d}, but, although it seems commonplace among physicists, mathematicians hardly ever use that. I want to use notation that is standard among mathematicians (unless there were some instance in which for some reason I actually disagree with it). – Michael Hardy Jul 15 '16 at 20:23
  • @PeterGrill : What if you want f(x),\Delta x? Would you forgo the spacing? How about \frac{\partial^2 f}{\partial x,\partial y} ? No space between the two partials? – Michael Hardy Jul 15 '16 at 20:26
  • 1
    For several more lines use the \hphantom (or define a macro fork it). Adding spacing such as \, is a matter of taste, but I highly recommend you define a macro for \dx so that it is consistent. – Peter Grill Jul 15 '16 at 20:32
  • . . . and besides, if one does write \mathrm{d}, I'd still put the space there: f(x),\mathrm{d}x or maybe f(x)~\mathrm{d}x. – Michael Hardy Jul 15 '16 at 20:32
  • The utility of the \dx macro is noted for future reference. There's still the thing about partials and capital Delta. – Michael Hardy Jul 15 '16 at 20:34

1 Answers1

6

You can use \negphantom (see Negative phantom inside equations) together with \hphantom:

\documentclass{article}
\usepackage{amsmath}

\newcommand{\diff}{\mathop{}\!d}

\makeatletter
\newlength{\negph@wd}
\DeclareRobustCommand{\negphantom}[1]{%
  \ifmmode
    \mathpalette\negph@math{#1}%
  \else
    \negph@do{#1}%
  \fi
}
\newcommand{\negph@math}[2]{\negph@do{$\m@th#1#2$}}
\newcommand{\negph@do}[1]{%
  \settowidth{\negph@wd}{#1}%
  \hspace*{-\negph@wd}%
}
\makeatother


\begin{document}

\begin{align} 
\int \arctan x \diff x = \int u\diff x 
&= \negphantom{\int u\diff x = {}}
   \overbrace{\hphantom{\int u\diff x = {}}xu - \int x\diff u}
     ^\text{integration by parts}
\\[10pt] 
&= x\arctan x - \int x\left( \frac{\diff x}{1+x^2} \right) 
\\[10pt] 
&= x\arctan x - \int x\left( \frac{\diff x}{1+x^2} \right) 
\\[10pt] 
&= x\arctan x - \int x\left( \frac{\diff x}{1+x^2} \right) 
\end{align}

\end{document}

Note the \diff command to automatically get the thin space.

enter image description here

egreg
  • 1,121,712