Ask Your Question
0

Centering the cells of a table and the use of tiny size

asked 2021-01-06 10:11:06 +0200

Cyrille gravatar image

updated 2021-01-18 19:11:05 +0200

slelievre gravatar image

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.

edit retag flag offensive close merge delete

Comments

Sorry I have understud ne1 must be a list of list.

Cyrille gravatar imageCyrille ( 2021-01-06 10:13:59 +0200 )edit

1 Answer

Sort by ยป oldest newest most voted
1

answered 2021-01-06 12:49:47 +0200

tmonteil gravatar image

updated 2021-01-18 19:17:20 +0200

slelievre gravatar image

Regarding 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   613
edit flag offensive delete link more

Comments

Ok. For a Latex user it's not self evident.

Cyrille gravatar imageCyrille ( 2021-01-06 18:20:58 +0200 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2021-01-06 10:11:06 +0200

Seen: 44 times

Last updated: Jan 18