ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Wed, 06 Jan 2021 18:20:58 +0100Centering the cells of a table and the use of tiny sizehttps://ask.sagemath.org/question/55144/centering-the-cells-of-a-table-and-the-use-of-tiny-size/I change my question to clarify.
In the following code (I have integrated the solution for `\tiny`):
First define a function:
def All_pref(cand=["A", "B", "C", "D"], code=1) :
ncand = len(cand)
Scand = sorted(Set(cand))
all_pref = Arrangements(Scand, ncand).list()
all_pref1 = [str(Word(x)) for x in all_pref]
if code == 1:
return ncand
if code == 2:
return all_pref1
Then use it:
cand = ["A", "B", "C", "D"]
ne1 = [18, 16, 14, 12, 11, 20, 19, 14, 16, 12, 2, 1, 0, 0, 20, 16, 13, 15, 11, 10, 9, 8, 7, 5]
ne = ne1
Ap = All_pref(cand, 2)
cond1 = ['$\\tiny${}{}{}{}$'.format(*w) for w in Ap]
cond2 = [""] + [r'${}$'.format(*w) for w in cand]
cond3 = [r'${}$'.format(*w) for w in cand]
t1 = table([ne], header_row=cond1)
rank = [[x.find(l) for x in Ap] for l in cand]
score_de_Borda = [[abs(x.find(l) - len(cand)) for x in Ap] for l in cand]
t2 = table(rank, header_row=cond1, header_column=cond2)
total_score_de_Borda = [add([score_de_Borda[j][i]*ne[i] for i in range(24)]) for j in range(len(cand))]
# t3 = table(total_score_de_Borda, header_column=cond3)
show(cond3,total_score_de_Borda)
everything works fine apart from the `header_column=cond3` (without it I have no problem) and as `show(cond3, total_score_de_Borda)` shows, the two elements have the same length.Wed, 06 Jan 2021 10:11:06 +0100https://ask.sagemath.org/question/55144/centering-the-cells-of-a-table-and-the-use-of-tiny-size/Comment by Cyrille for <p>I change my question to clarify.
In the following code (I have integrated the solution for <code>\tiny</code>):</p>
<p>First define a function:</p>
<pre><code>def All_pref(cand=["A", "B", "C", "D"], code=1) :
ncand = len(cand)
Scand = sorted(Set(cand))
all_pref = Arrangements(Scand, ncand).list()
all_pref1 = [str(Word(x)) for x in all_pref]
if code == 1:
return ncand
if code == 2:
return all_pref1
</code></pre>
<p>Then use it:</p>
<pre><code>cand = ["A", "B", "C", "D"]
ne1 = [18, 16, 14, 12, 11, 20, 19, 14, 16, 12, 2, 1, 0, 0, 20, 16, 13, 15, 11, 10, 9, 8, 7, 5]
ne = ne1
Ap = All_pref(cand, 2)
cond1 = ['$\\tiny${}{}{}{}$'.format(*w) for w in Ap]
cond2 = [""] + [r'${}$'.format(*w) for w in cand]
cond3 = [r'${}$'.format(*w) for w in cand]
t1 = table([ne], header_row=cond1)
rank = [[x.find(l) for x in Ap] for l in cand]
score_de_Borda = [[abs(x.find(l) - len(cand)) for x in Ap] for l in cand]
t2 = table(rank, header_row=cond1, header_column=cond2)
total_score_de_Borda = [add([score_de_Borda[j][i]*ne[i] for i in range(24)]) for j in range(len(cand))]
# t3 = table(total_score_de_Borda, header_column=cond3)
show(cond3,total_score_de_Borda)
</code></pre>
<p>everything works fine apart from the <code>header_column=cond3</code> (without it I have no problem) and as <code>show(cond3, total_score_de_Borda)</code> shows, the two elements have the same length.</p>
https://ask.sagemath.org/question/55144/centering-the-cells-of-a-table-and-the-use-of-tiny-size/?comment=55145#post-id-55145Sorry I have understud `ne1` must be a list of list.Wed, 06 Jan 2021 10:13:59 +0100https://ask.sagemath.org/question/55144/centering-the-cells-of-a-table-and-the-use-of-tiny-size/?comment=55145#post-id-55145Answer by tmonteil for <p>I change my question to clarify.
In the following code (I have integrated the solution for <code>\tiny</code>):</p>
<p>First define a function:</p>
<pre><code>def All_pref(cand=["A", "B", "C", "D"], code=1) :
ncand = len(cand)
Scand = sorted(Set(cand))
all_pref = Arrangements(Scand, ncand).list()
all_pref1 = [str(Word(x)) for x in all_pref]
if code == 1:
return ncand
if code == 2:
return all_pref1
</code></pre>
<p>Then use it:</p>
<pre><code>cand = ["A", "B", "C", "D"]
ne1 = [18, 16, 14, 12, 11, 20, 19, 14, 16, 12, 2, 1, 0, 0, 20, 16, 13, 15, 11, 10, 9, 8, 7, 5]
ne = ne1
Ap = All_pref(cand, 2)
cond1 = ['$\\tiny${}{}{}{}$'.format(*w) for w in Ap]
cond2 = [""] + [r'${}$'.format(*w) for w in cand]
cond3 = [r'${}$'.format(*w) for w in cand]
t1 = table([ne], header_row=cond1)
rank = [[x.find(l) for x in Ap] for l in cand]
score_de_Borda = [[abs(x.find(l) - len(cand)) for x in Ap] for l in cand]
t2 = table(rank, header_row=cond1, header_column=cond2)
total_score_de_Borda = [add([score_de_Borda[j][i]*ne[i] for i in range(24)]) for j in range(len(cand))]
# t3 = table(total_score_de_Borda, header_column=cond3)
show(cond3,total_score_de_Borda)
</code></pre>
<p>everything works fine apart from the <code>header_column=cond3</code> (without it I have no problem) and as <code>show(cond3, total_score_de_Borda)</code> shows, the two elements have the same length.</p>
https://ask.sagemath.org/question/55144/centering-the-cells-of-a-table-and-the-use-of-tiny-size/?answer=55149#post-id-55149Regarding the "`\tiny` doesn't work" part, you should add
a `$` before the LaTeX formula and you should either
escape the `\` with another `\` or use a raw string:
sage: cond1 = ['$\\tiny{}{}{}{}$'.format(*w) for w in Ap]
sage: cond1 = [r'$\tiny{}{}{}{}$'.format(*w) for w in Ap]
Regarding the table, it needs a list of lists, not just a list,
so use extra brackets; and you want headers for the columns,
so they form a row of headers or "header row".
sage: t3 = table([total_score_de_Borda], header_row=cond3)
sage: t3
$A$ $B$ $C$ $D$
+-----+-----+-----+-----+
717 691 669 613Wed, 06 Jan 2021 12:49:47 +0100https://ask.sagemath.org/question/55144/centering-the-cells-of-a-table-and-the-use-of-tiny-size/?answer=55149#post-id-55149Comment by Cyrille for <p>Regarding the "<code>\tiny</code> doesn't work" part, you should add
a <code>$</code> before the LaTeX formula and you should either
escape the <code>\</code> with another <code>\</code> or use a raw string:</p>
<pre><code>sage: cond1 = ['$\\tiny{}{}{}{}$'.format(*w) for w in Ap]
sage: cond1 = [r'$\tiny{}{}{}{}$'.format(*w) for w in Ap]
</code></pre>
<p>Regarding the table, it needs a list of lists, not just a list,
so use extra brackets; and you want headers for the columns,
so they form a row of headers or "header row".</p>
<pre><code>sage: t3 = table([total_score_de_Borda], header_row=cond3)
sage: t3
$A$ $B$ $C$ $D$
+-----+-----+-----+-----+
717 691 669 613
</code></pre>
https://ask.sagemath.org/question/55144/centering-the-cells-of-a-table-and-the-use-of-tiny-size/?comment=55162#post-id-55162Ok. For a Latex user it's not self evident.Wed, 06 Jan 2021 18:20:58 +0100https://ask.sagemath.org/question/55144/centering-the-cells-of-a-table-and-the-use-of-tiny-size/?comment=55162#post-id-55162