# Subscripts in partial derivatives

I would like to print the partial derivative operator $\frac{\partial}{\partial k_x}$, but the spacing and the length of the bar bug me a little. I would really like the fraction to be typeset as $\frac{\partial}{\partial k}$ (which has a shorter bar and the upper $\partial$ further to the left), with the subscript ${}_x$ added afterwards.

I'm definitely sure this is possible. What would be the quickest, cleanest way?

-

\documentclass{article}
\begin{document}

1 $\frac{\partial}{\partial k}$

2 $\frac{\partial}{\partial k_x}$

3 $\frac{\partial}{\partial k}_{\scriptscriptstyle x}$

4 $\frac{\partial}{\partial k_{\rlap{$\scriptscriptstyle x$}}}$

\end{document}

-
Your solution 4 does what the OP wants, but it has the same drawback (mentioned by Matthew Leingang) as A. Ellett's answer. – Hendrik Vogt Feb 19 '13 at 11:24
yes true any version that hides the width inside the frac ought to add some white space after the frac to compensate. – David Carlisle Feb 19 '13 at 11:46

Using mathtools there is \mathmakebox which behaves much like \makebox but is sensitive to the mathematical context and will set things correctly:

Or as @Qrrbrbirlbel suggested, you can use \mathrlap and its ilk. I illustrate both \mathmakebox and \mathllap here (I've never like the way the numerator and denominator are off set when you want a negative in the numerator).

\documentclass{article}
\usepackage{amsmath,amssymb,mathtools}
\pagestyle{empty}
\begin{document}
$\frac{\partial}{\partial k_{\mathmakebox[0pt][l]{x}}}$

$\frac{\mathllap{-}1}{2}$
\end{document}


What I like about \mathmakebox is that it allows you define the width of the box and the positioning. Probably for your purposes, \mathrlap is all you need.

-
Hint: \mathrlap – Qrrbrbirlbel Feb 18 '13 at 18:04
But the subscripted x now crashes into whatever would follow this symbol. Consider \frac{\partial}{\partial k_{\mathmakebox[0pt][l]{x}}}\frac{k_x}{k_x + k_y}. Maybe you should add a \phantom{\scriptstyle x}? – Matthew Leingang Feb 18 '13 at 18:07
@MatthewLeingang indeed. I was a bit hasty and neglected to think of the spacing issue. – A.Ellett Feb 18 '13 at 18:12
Should have said \scriptscriptstyle x, sorry. – Matthew Leingang Feb 18 '13 at 18:15
why to load both amsmath and mathtools? – Harish Kumar Feb 18 '13 at 22:43

Here's a solution that works with \mathrlap from the mathtools package, combined with a \phantom to get proper spacing after the derivative. (It's not so efficient since I nested \mathrlap.)

\documentclass{article}
\usepackage{mathtools}
\newcommand*\xpartial[2]{%
\mathrlap{\frac{\partial}{\partial #1_{\mathrlap{#2}}}}%
\phantom{\frac{\partial}{\partial #1_{#2}}}%
}
\begin{document}
$\frac{\partial}{\partial k_x} g$ versus $\xpartial{k}{x} g$
\end{document}


(By the way, I would have expected x_k, not k_x in the denominator.)

-
The derivative is with respect to the $x$ component of a wave vector $\mathbf{k}$. – E.P. Feb 28 '13 at 17:41

Bingo! Got it. Some negative space does it: $\frac{\partial}{\partial k_x\!\!\!}\,$

-
No, in all honesty, you did not get it: Using \!\!\! and \, just "almost next to each other" shows that something is wrong. – yo' Feb 28 '13 at 16:10
@tohecz: The only problems I see here is that 1. one has to guess the spacing and 2. the positive spacing with \, is too small so that one can have an overlap. The \! and \, are only almost next to each other, and this makes a lot of sense. – Hendrik Vogt Feb 28 '13 at 19:50