请问如何改善此代码(空间和对齐),我想要大部分并且全部对齐
\documentclass[12pt,a4paper,openany]{book}
\usepackage{mathrsfs}
\usepackage{amsmath,amssymb,amsthm}
\newcommand{\dropsign}[1]{\smash{\llap{\raisebox{-.5\normalbaselineskip}{$#1$\hspace{2\arraycolsep}}}}}
\begin{document}
\[
\Large
\begin{array}{r|r}
\dropsign{-} x+\frac{x^3}{6}+\frac{x^5}{120} &
1+\phantom{6}\frac{x^2}{2}+\frac{x^4}{24} \\
\cline{2-2}
x+\frac{x^3}{2}+\phantom{}\frac{x^5}{24} & -\frac{x^3}{3}+\frac{2x^5}{15}\\
\cline{1-1}
\\ [\dimexpr-\normalbaselineskip+\jot]
\dropsign{-} -\frac{x^3}{3}-\frac{x^5}{30}\phantom{6}\\ -\frac{x^3}{3}-\frac{x^5}{6}-\frac{x^7}{72}\\
\cline{1-1}
\\ [\dimexpr-\normalbaselineskip+\jot]
\dropsign{-}\frac{2x^5}{15}+\frac{x^7}{15}\\
\frac{2x^5}{15}+\frac{x^7}{15}+\frac{x^9}{180}\\
\cline{1-1}
\\ [\dimexpr-\normalbaselineskip+\jot]
-\frac{19x^7}{36}-\frac{x^9}{180}
\end{array}
\]
\end{document}
答案1
我提出了这个解决方案,基于一个有两列的数组,以及alignedat
每列中的一个环境:
\documentclass[12pt,a4paper,openany]{book}
\usepackage{xcolor}
\usepackage{mathrsfs}
\usepackage{mathtools, amssymb, amsthm}
\usepackage{booktabs}
\begin{document}
\[
\begin{array}{r!{\vrule width 0.8pt}l}
\begin{alignedat}[t]{5}
& & x+\frac{x^3}{6} &&{}+\frac{x^5}{120} & & & & &\\
\noalign{\vskip-2ex}
\ArrowBetweenLines[\color{red}\boldsymbol{-}]%
\noalign{\vskip-2ex}
& & x+\frac{x^3}{2} & & {}+\frac{x^5}{24}& \\
\cmidrule{3-6}
& & -\frac{x^3}{3} &&{}-\frac{x^5}{30}& \\
\noalign{\vskip-2ex}
\ArrowBetweenLines[\color{red}\boldsymbol{-}]%
\noalign{\vskip-2ex}
& &-\frac{x^3}{3}&& {}-\frac{x^5}{6}& & {}-\frac{x^7}{72} & \\
\cmidrule(l{1em}r{-0.5em}){3-8}
& & & &\phantom{-}\frac{2x^5}{15} & & {}+\frac{x^7}{72} & \\
\noalign{\vskip-2ex}
\ArrowBetweenLines[\color{red}\boldsymbol{-}]%
\noalign{\vskip-2ex}
& & & & \phantom{-}\frac{2x^5}{15} & &{}+\frac{x^7}{15}& & & {}+\frac{x^9}{180} \\
\cmidrule(l{1em}r{-0.25em}){5-10}
& & & & & &{}-\frac{19x^7}{360} & & & {}-\frac{x^9}{180} \
\end{alignedat}
&
\begin{alignedat}[t]{6}
1 & {}+ \frac{x^2}{2} & & {}+ \frac{x^4}{24}\\
\cmidrule[0.8pt](l{-5pt}r{-1em}){1-4}
x & {}- \frac{x^3}{3} & & {} + \frac{2x^5}{15}{}
\end{alignedat}\\
\end{array}
\]
\end{document}