Adjust row and column widths in Confluence Tables

Is it really possible that I have no control over the width of a column or a row in a table in confluence? It seems like the only possible formatting is adding or removing a row.

 

3 answers

This widget could not be displayed.

That is sadly correct. You can adjust widths using table markup or the table et al macros.

Also, be sure to vote for this enhancement: https://jira.atlassian.com/browse/CONF-3393

This widget could not be displayed.
Davin Studer Community Champion Jul 24, 2015

Here is a user macro that I created to help make up for the lack of some of these kinds of features.

Macro Name:
advanced_tables

Macro Title:
Advanced Tables

Macro Body Processing:
Rendered

Template:

## Developed by: Davin Studer
## Date created: 04/30/2014
 
## @param AutoNumber:title=Autonumber Rows|type=boolean|desc=This will autonumber the rows in the table that are not heading rows.|default=false
## @param HeadingReset:title=Reset Count|type=boolean|desc=This will reset the count each time a heading row is encountered. (only applicable if Autonumber Rows is checked)|default=false
## @param Zebra:title=Zebra Table|type=boolean|desc=This will alternate the color of the table's rows.|default=false
## @param NoScroll:title=No Table Scroll|type=boolean|desc=This will turn off the scroll bat that is at the bottom of the table in favor of one always at the bottom of the page. This is useful for tables that are wider than the page.|default=false
## @param Width:title=Table Width|type=string|required=false|desc=This will set the width of the table. Acceptable values are in % or px.
## @param Class:title=CSS Class|type=string|required=false|desc=This will assign a css class to the table.
## @param ColWidth:title=Column Widths|type=string|required=false|desc=Use a comma separated list of column widths for the table. Acceptable values are in % or px.
 
#set( $id = $action.dateFormatter.calendar.timeInMillis )
 
<div id="table$id">$body</div>
 
<style type="text/css">
#if ( $paramZebra == true )
#table$id tr:nth-child(odd) {background-color: #E0F0FF;}
#table$id tr:nth-child(even) {background-color: #FFFFFF;}
#end
#if ( $paramNoScroll == true )
#table$id .table-wrap {overflow-x: visible;}
#end
</style>
<script type="text/javascript">
AJS.toInit(function(){
    AJS.$('#table$id table').each(function(){
        ################
        ## Autonumber ##
        ################
        #if ( $paramAutoNumber == true )
        var number = true;
        #else
        var number = false;
        #end
        
        #if ( $paramHeadingReset == true )
        var reset = true;
        #else
        var reset = false;
        #end
        
        ################
        ## Width      ##
        ################
        #if ( $paramWidth && $paramWidth != "" )
        var tblWidth = '$paramWidth';
        #else
        var tblWidth = '';
        #end
        
        ################
        ## Class      ##
        ################
        #if ( $paramClass && $paramClass != "" )
        var cssClass = '$paramClass';
        #else
        var cssClass = '';
        #end
        ################
        ## Col Width  ##
        ################
        #if ( $paramColWidth && $paramColWidth != "" )
        var colWidth = '$paramColWidth';
        #else
        var colWidth = '';
        #end
        if(number) {
            var count = 1;
            
            AJS.$('tr', this).each(function(){
                if(AJS.$('th',this).length != 0) {
                    AJS.$(this).prepend('<th class="confluenceTh"> </th>');
                    if(reset) {
                        count = 1;
                    }
                } else {
                    AJS.$(this).prepend('<td class="confluenceTd">' + count + '</td>');
                    count++;
                }
            });
        }
        
        if(tblWidth != "") {
            AJS.$(this).css('width', tblWidth);
        }
        
        if(cssClass != "") {
            AJS.$(this).addClass(cssClass);
        }
        
        if(colWidth != "") {
            var arrColWidth = colWidth.split(',');
            var firstRow = AJS.$('tr:first-child', this);
            var tdorth = AJS.$('td', firstRow).length == 0 ? 'th' : 'td';
            
            AJS.$(tdorth, firstRow).each(function(index){
                if(index + 1 <= arrColWidth.length && arrColWidth[index].trim().search(/^([0-9]+)(%|px)$/) != -1) {
                    AJS.$(this).css('width', arrColWidth[index].trim());
                }
            });
        }
    });
});
</script>

Crazy great stuff, that!

This widget could not be displayed.

I've found an easy way of doing this, for Server 5.7.3. 

All you have to do is:

Add width="n" into the <th> tag at the beginning of the code.

For example:

<th width="100">Column Name</th>

In the code this looks like:

<table>
<tbody>
<tr>
<th width="200">Field</th>
<th>Description</th>
</tr>

Do this for all columns or just the one you want to keep at a fixed width.

So for two columns you could have:

<table>
<tbody>
<tr>
<th width="200">Field</th>
 <th width="500">Description</th>
 <th>Description</th>
</tr>

I did this yesterday and it's still working today, so it must be right! smile

Cheers.

Suggest an answer

Log in or Sign up to answer
Atlassian Summit 2018

Meet the community IRL

Atlassian Summit is an excellent opportunity for in-person support, training, and networking.

Learn more
Community showcase
Published yesterday in Confluence

Add-on evaluation with confluence templates

Atlassian market place contains number of Apps/Addons which improves the capability of out of the box Atlassian products. It is good to follow a plugin evaluation process before install add-ons. So t...

38 views 5 3
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you