4

I'm trying to typeset the simplification/expansion of a fraction using the notation below, but I would like the numerator to be centered and the 5\cdot 4) to be to the left and above of the entire fraction without the division line being distorted or stretched in any way by it.

enter image description here

I figured that if I could declare a set of invisible delimiters using \DeclarePairedDelimiter{<command>}{<left delimiter>}{<right delimiter>} the task would be simple, since I could simply place the fraction inside the delimiters and place the 5\cdot 4) relative to the entire block, but I'm not sure if this is possible. Using \DeclarePairedDelimiter{\invis}{.}{.} didn't work.

I'm open to other solutions, but if someone has a solution using this particular method, it would make my life a lot simpler.

5

I would like the numerator to be centered and the 5\cdot 4) to be to the left and above of the entire fraction without the division line being distorted or stretched in any way by it.

APPROACH 1

In this approach, the superscript will precede the full fraction, rather than just the numerator. It will also take up horizontal space, rather than be a lapped quantity.

EDITED to allow [l]eft or [r]ight positioning with use of optional argument.

\documentclass{article}
\usepackage{stackengine}
\newcommand\simpex[3][l]{%
  \savestack\thefrac{$\displaystyle#3$}
  \ifx l#1\rule{0pt}{\ht\thefraccontent}^{#2)\!}\fi
  #3
  \ifx r#1\rule{0pt}{\ht\thefraccontent}^{\!(#2}\fi
}
\begin{document}
\[
\simpex{5\cdot 4}{\frac{1}{17}}
\textrm{ versus }
\simpex[r]{5\cdot 4}{\frac{1}{17}}
\]
\end{document}

enter image description here

APPROACH 2

Being a \mathllap, there could be spacing issues with adjacent material. However, without more information on the use cases, it is hard to develop a remedy for that in the blind.

For example, will it always lead a line? Will it always be part of a fraction? If so, will it always be in the numerator? etc.

\documentclass{article}
\usepackage{mathtools}
\begin{document}
\[
\frac{\mathllap{^{5\cdot 4)}}1}{17}
\]
\end{document}

enter image description here

  • What if I wanted achieve the same thing, but on the right side of the fraction? So instead of 5 \cdot 4) being on the above left, I would have (5 \cdot 4 on the above right side of the fraction. – SeSodesa Oct 3 '18 at 14:24
  • @TheSodesa See my edit. I introduce an optional argument to handle left or right positioning. – Steven B. Segletes Oct 3 '18 at 14:35
4

Is it one of these you want? They use stackengine:

\documentclass{article}
\usepackage{mathtools}
\usepackage[usestackEOL]{stackengine}
\setstackgap{S}{1pt}
\begin{document}

\[ A = \stackMath\Shortstack{\mathllap{\scriptstyle 5\cdot 4)}\\\dfrac{1}{17}} \]%

\[ A = \stackMath
\setstackgap{S}{-1ex}\Shortstack{\mathllap{\scriptstyle 5\cdot 4)\:}\\\dfrac{1}{17}} \]%

\end{document} 

enter image description here

Edit: This code uses only mathtools:

\[ A = \prescript{\mathllap{5\cdot 4)}\mkern-8mu}{}{\frac{1}{17}} \]%

enter image description here

4

Here's a solution that employs just the LaTeX macro \raisebox. The macro \mysimp is defined to take three arguments, one of which is optional. The optional argument sets the vertical displacement by which the first mandatory argument must be raised. The default value of the vertical displacement is 3ex, which seems about right if the final argument contains a display-style fractional term.

enter image description here

Remove the \scriptstyle directive if the left-superscript term should be typeset in text-style and not in \scriptstyle.

\documentclass{article}
\newcommand{\mysimp}[3][3ex]{\raisebox{#1}{$\scriptstyle #2$} \! #3}
\begin{document}
\[
\mysimp{5\cdot4)}{\frac{1}{17}} \qquad \mysimp[1.25ex]{uv}{abc}
\]
\end{document}
  • 1
    @PhelypeOleinik - Thanks for the edit! – Mico Oct 3 '18 at 14:35
  • Why not \raisebox? – egreg Oct 3 '18 at 17:35
  • @egreg - Thanks for the suggestion. I went ahead and modified the \mysimp macro so that it uses \raisebox instead of \raise and \hbox. – Mico Oct 3 '18 at 17:48
  • 1
    You're a really good boy. ;-) – egreg Oct 3 '18 at 17:49
2

Here's a solution with only LaTeX macros (and \mathpalette).

\documentclass{article}
\usepackage{amsmath}

\makeatletter
\newcommand{\aboveleft}[2]{{\mathpalette\above@left{{#1}{#2}}}}
\newcommand{\above@left}[2]{\above@@left{#1}#2}
\newcommand{\above@@left}[3]{%
  \sbox\z@{$\m@th#1#3$}%
  \raisebox{0.7\ht\z@}{$\m@th\dem@te{#1}#2$}%
  \box\z@
}
\newcommand{\dem@te}[1]{%
  \ifx#1\displaystyle\scriptstyle\else\scriptscriptstyle\fi
}
\makeatother

\begin{document}

\[
\aboveleft{5\cdot4)}{\frac{1}{17}}
\]
In text it is also possible $\aboveleft{5\cdot4)}{\frac{1}{17}}$

\end{document}

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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