# Multivariate polynomial long division in LaTex

How do I typeset polynomial long division with multiple variables using LaTeX? I want to do polynomial long division with two and more divisors. I know there was a similar question already answered here, but the answer couldn't help since I want the long division to look like that:

I could already solve it for when having only one divisor, but when having two it doesn't look good anymore. Can somebody help me fixing that?

This is the code I currently have:

\usepackage[ngerman]{babel}
\usepackage{latexsym}
\usepackage{amsfonts}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{amsthm}
\usepackage{bbm}
%\usepackage{enumerate}
\usepackage{enumitem}
\usepackage{MnSymbol}
\usepackage{listings}
\usepackage{mdframed}
\usepackage{pgfplots}
\usepackage{todonotes}
\usepackage[utf8]{inputenc} %deutsche Umlaute
\input longdiv.tex
\usepackage[]{algorithm2e}

\newcommand\Mydiv[2]{%
\strut#1$\kern.25em\smash{\raise.3ex\hbox{$\big)$}}$\mkern-8mu
\overline{\enspace\strut#2}}

$$\begin{array}{rll} q_1: x \phantom{000000000} \\[-3pt] q_2: -1 \phantom{00000000} \\[-3pt] \Mydiv{\begin{array}{r} xy-1\\ x+y \end{array}}{x^2y-2x-y+4} \\[-3pt] \underline{x^2y- \phantom{0} x \phantom{000000}} \\ 4 \\[-3pt] \end{array}$$


This gives me this result: I don't like the way the two divisors are taller than the bracet, but I couldn't figure out how to fix it... Thank you very much already!

• Welcome to TeX.SE! It is good that you have provided a code example, but it would be helpful when you make the example compilable, i.e., when somebody copy-pastes the code to a new file on their own machine and runs LaTeX on it it should result in the output that you show (currently it shows an error: ! LaTeX Error: \usepackage before \documentclass.). Also, when you include an image of the output (which is helpful), then a real screenshot might be easier to read than a photo. – Marijn Aug 28 '19 at 17:20
• Potential duplicate: Multivariate polynomial long division using LaTeX. – barbara beeton Aug 29 '19 at 2:15
• Arrays are normally centered relative to each other. Try using [t]. – John Kormylo Aug 29 '19 at 16:40