A variation on my solution to Command for the table Ruffini-Horner algorithm
The optional argument to \ruffini sets gapes for the cells when you have to accommodate large objects
\documentclass{article}
\usepackage{xparse,array,makecell}
\ExplSyntaxOn
\NewDocumentCommand{\ruffini}{O{0pt}mmmm}
{% #1 = gape, #2 = polynomial, #3 = divisor, #4 = middle row, #5 = result
\franklin_ruffini:nnnnn { #2 } { #3 } { #4 } { #5 } { #1 }
}
\seq_new:N \l_franklin_temp_seq
\tl_new:N \l_franklin_scheme_tl
\int_new:N \l_franklin_degree_int
\cs_new_protected:Npn \franklin_ruffini:nnnnn #1 #2 #3 #4 #5
{
\group_begin:
\makegapedcells
\setcellgapes{#5}
% Start the first row
\tl_set:Nn \l_franklin_scheme_tl { & }
% Split the list of coefficients
\seq_set_split:Nnn \l_franklin_temp_seq { , } { #1 }
% Remember the number of columns
\int_set:Nn \l_franklin_degree_int { \seq_count:N \l_franklin_temp_seq }
% Fill the first row
\tl_put_right:Nx \l_franklin_scheme_tl
{ \seq_use:Nn \l_franklin_temp_seq { & } }
% End the first row and leave two empty places in the next
\tl_put_right:Nn \l_franklin_scheme_tl { \\ #2 & & }
% Split the list of coefficients and fill the second row
\seq_set_split:Nnn \l_franklin_temp_seq { , } { #3 }
\tl_put_right:Nx \l_franklin_scheme_tl
{ \seq_use:Nn \l_franklin_temp_seq { & } }
% End the second row
\tl_put_right:Nn \l_franklin_scheme_tl { \\ \hline }
% Split and fill the third row
\seq_set_split:Nnn \l_franklin_temp_seq { , } { #4 }
\tl_put_right:Nx \l_franklin_scheme_tl
{ & \seq_use:Nn \l_franklin_temp_seq { & } }
% Start the array (with \use:x because the array package
% doesn't expand the argument)
\use:x
{
\exp_not:n { \begin{array} } { r | *{\int_eval:n { \l_franklin_degree_int - 1 }} { r } | r }
}
% Body of the array and finish
\tl_use:N \l_franklin_scheme_tl
\end{array}
\group_end:
}
\ExplSyntaxOff
\begin{document}
\[
\ruffini[2pt]{1,-2,1,-\frac{4}{27}}
{\frac{1}{3}}
{\frac{1}{3},-\frac{5}{9},\frac{4}{27}}
{1,-\frac{5}{3},\frac{4}{9},0}
\qquad
\ruffini{1,-6,11,-6}{2}{2,-8,6}{1,-4,3,0}
\]
\end{document}
