# How to move the lines in arrays

I wanted to apply Ruffini's rule but since I'm using fractions it's all crowded and messy. Is there a way to leave more space between the lines?

\begin{equation*}
\begin{array}{c|c c c|c}
&1 &-2  &1 &-\frac{4}{27}\\
\frac{1}{3} & &\frac{1}{3} &-\frac{5}{9} &\frac{4}{27}\\
\hline
& 1 &-\frac{5}{3} &\frac{4}{9} &0\\
\end{array}
\end{equation*}

• This seems a duplicate of tex.stackexchange.com/q/122699/4427 I'll add a variation of my solution to be more “Italian style”. – egreg Apr 20 at 13:36
• @egreg; I don't think the link tackles the specific problem of fractions in tables: the O.P. said it's all crowded, which seems to mean fractions touch the horizontal lines. – Bernard Apr 20 at 13:49

A solution with the cellspace package, to add a minimal padding at the top and bottom of cells in columns with specifier prefixed with the letter S (or C if you load siunitx). I also loaded nccmath to have medium-sized fractions, which look nicer in this context, from my point of view:

\documentclass[a4paper,12pt]{article}
\usepackage{cellspace}
\setlength{\cellspacetoplimit}{4pt}
\setlength{\cellspacebottomlimit}{4pt}

\usepackage{amsmath, nccmath}

\begin{document}

$\begin{array}{>{}Sr<{}|*{3}{>{}Sr<{}}|>{}Sr<{}} &1 &-2 &1 &-\mfrac{4}{27} \\ \mfrac{1}{3} & &\mfrac{1}{3} &-\mfrac{5}{9} &\mfrac{4}{27} \\ \hline & 1 &-\mfrac{5}{3} &\mfrac{4}{9} & 0 \end{array}$

\end{document}


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}


with use of makecell:

\documentclass[a4paper,12pt]{article}
\usepackage{makecell}
\usepackage{nccmath}

\begin{document}
$\setcellgapes{3pt} \makegapedcells \begin{array}{r|*{3}{r}|r} & 1 & -2 & 1 & -\mfrac{4}{27} \\ \mfrac{1}{3} & & \mfrac{1}{3} & -\mfrac{5}{9} & \mfrac{4}{27} \\ \hline & 1 & -\mfrac{5}{3} & \mfrac{4}{9} & 0 \end{array}$
\end{document}