(To be fair, it's not Mathematica that is 'misbehaving'; this is actually down to my limited coding skills.)

I have the following Table:

Module[{l = 5}, 
 table1 = Table[RandomInteger[{-100, 100}]/
      RandomInteger[{-100, 100}], {n, 1, l}]; 
 table2 = ContinuedFraction[table1]; 
  TableForm[Transpose[{table1, table2}], 
   TableHeadings -> {None, {"R", "CF of R"}}]]

The ContinuedFraction function produces the correct data, but not in Table-friendly form. The "CF of R" column lists the continued fractions vertically. I want some form of horizontal representation to make the Table more readable. In a totally ideal world, I'd like the continued fractions to appear as (for example)


i.e., reformatted so that (a) the continued fraction appears as a row in the Table, not a column-per-item, and (b) it uses standard traditional formatting.

How do I do this?


If I understand you:

cfform[{b_, d___}] := Row[{"[", b, ";", ##, "]"}] & @@ Riffle[{d}, ","]

TableForm[{table1, cfform /@ table2}\[Transpose], 
 TableHeadings -> {None, {"R", "CF of R"}}]

enter image description here

  • 1
    $\begingroup$ Hi @Mr Wizard. Many thanks. $\endgroup$ – Richard Burke-Ward Dec 11 '19 at 12:42

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.