Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

How can I set width of Confluence Cloud table columns using Confluence REST API?

Bruce Wilcox March 18, 2020

The below html is not working. text-align works but not width. Columns have equal widths.

<table>
<tr>
<th style="text-align: center; font-size: large; width: 5%;">
#
</th>
<th style="text-align: center; font-size: large; width: 10%;">
Number
</th>
<th style="text-align: center; font-size: large; width: 40%;">
Title
</th>
<th style="text-align: center; font-size: large; width: 10%;">
FDX
</th>
<th style="text-align: center; font-size: large; width: 10%;">
OFX
</th>
<th style="text-align: center; font-size: large; width: 10%;">
FIRE
</th>
</tr>
...

 

1 answer

1 accepted

2 votes
Answer accepted
Diego
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
March 20, 2020

Hello @Bruce Wilcox ! As I understand, you need to manually set the Table Column width via REST API.

Looking at your lines, I see that everything should be working, CSS/HTML wise. If we take a look at a 3x3 table created in Confluence, here is what the syntax looks like:

TableSyntax.jpg

Here is the table:

TableImage.jpg

With this in mind, we can apply the desired width to the <col> tag inside the <colgroup> tag. This element should support size in %.

Try to remove the width parameter from the style in your table headers<th> and move it to the <col> inside <colgroup>.

I hope this helps you out, Bruce! Looking forward to your reply.

Bruce Wilcox March 20, 2020

Thank you very much, Diego.

I changed to the following and it works. 

<table>
<colgroup>
<col style="width: 36px;" />
<col style="width: 48px;" />
<col style="width: 480px;" />
<col style="width: 36px;" />
<col style="width: 36px;" />
<col style="width: 36px;" />
</colgroup>
<tr>

I find that (1) %'s do not work and (2) using pixels actually sets proportional not absolute widths.

I also find that xhtml is required. You must close empty tags with />.

Thank you again.

Like # people like this
Diego
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
March 20, 2020

Great to know that you were able to create the table, @Bruce Wilcox ! Also, thank you very much for sharing those tips here with the community.

Like Mandy Ross likes this
Duane Kuroda March 19, 2024

@Diego I tried nearly the same <colgroup><col> structure as above using px widths, and I don't get the same effect when creating a cloud confluence page via API. All my columns end up the same width. Note: I am creating the table in an expanded section, so if the two are not compatible, that would be good to know. 

Is there any sample code you can share where I can create a test page that works as stated in the 'fix' above?

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
STANDARD
TAGS
AUG Leaders

Atlassian Community Events