none
Table Style: "First column" alignment doesn't apply to top left cell in Header row RRS feed

  • Question

  • In a corporate template, I'd like all of the table cells to be center aligned, except for the first column, which should be left aligned. I also need specific shading and borders for a header row.

    So in the Table Style I formatted the "Whole Table" to Align Center, formatted the borders and shading to the "Header Row", and formatted the "First Column" to Align Center Left. This gives the desired effect except in the first row first column (i.e., the top left cell). This cell is aligned center (like the header row) rather than aligned left like the first column, which isn't very useful for a column header.

    Can I define the Table Style so that the top left cell behaves like it's in the first column rather than just in the header row? (I know this can be done by manually changing the top left cell, but I'd like to avoid manual formatting, since this is for a corporate template and users probably won't do the manual formatting).

    Thanks very much.

    Wednesday, July 2, 2014 2:26 PM

Answers

  • I'd like to do it without a macro, i.e., by defining the table style within the template instead.

    How about making a new Table Style, and apply the table style on the table you want?

    As you can see, if you apply the style for the table, then the top left cell is align left just as you expect.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Friday, July 4, 2014 3:23 AM
    Moderator

All replies

  • I know this can be done by manually changing the top left cell, but I'd like to avoid manual formatting, since this is for a corporate template and users probably won't do the manual formatting

    Do you mean you want to do it in VBA code? I just made an example with this VBA code which could autumatically format the "Whole Table" to align center, then set the shading to the "Header Row", and finally format the "First Column" to Align Left. It works fine. The top left cell aligns left as the first column does. The result is as this picture suggests:

    The VBA code is here:

    Dim tbl As Table
        
        Set tbl = ActiveDocument.Tables.Add(ActiveDocument.Range(0, 0), 4, 3)
        With tbl
            .Borders.InsideLineStyle = wdLineStyleSingle
            .Borders.OutsideLineStyle = wdLineStyleSingle
            
            'Set the alignment for all cells
            For i = 1 To .Rows.Count
                For j = 1 To .Columns.Count
                    .Cell(i, j).Range.Text = "abc"
                    .Cell(i, j).Range.ParagraphFormat.Alignment = wdAlignParagraphCenter
                Next j
            Next i
            
            'Set the shading for the header row
            .Rows(1).Shading.BackgroundPatternColorIndex = wdGray25
            
            'Set the alignment for the first column
            For k = 1 To .Columns(1).Cells.Count
                .Cell(k, 1).Range.ParagraphFormat.Alignment = wdAlignParagraphLeft
            Next k
        End With

    If I misunderstand you, please let me know.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Thursday, July 3, 2014 3:35 AM
    Moderator
  • I'd like to do it without a macro, i.e., by defining the table style within the template instead.
    Thursday, July 3, 2014 1:18 PM
  • I tried using a macro to modify the first column and the top left cell of the table style:

    Sub EditTableStyle()
    
    With ActiveDocument.Styles("JASCO Table")
        .ParagraphFormat.Alignment = wdAlignParagraphCenter
        .Table.Condition(wdFirstColumn).ParagraphFormat.Alignment = wdAlignParagraphLeft
        .Table.Condition(wdNWCell).ParagraphFormat.Alignment = wdAlignParagraphLeft
    End With
    
    End Sub

    This gives the correct alignment, but the table style reverts itself back to what it was if I right-click the table style in the Table Styles menu on the ribbon (e.g., to use the commands "Modify Table Style" or "Apply (and Clear Formatting)").

    Thursday, July 3, 2014 2:12 PM
  • I'd like to do it without a macro, i.e., by defining the table style within the template instead.

    How about making a new Table Style, and apply the table style on the table you want?

    As you can see, if you apply the style for the table, then the top left cell is align left just as you expect.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Friday, July 4, 2014 3:23 AM
    Moderator
  • Yes. Creating a new table style worked. I was trying to modify an existing style that had the header row defined as aligned centre, which was over-writing the alignment of the first column. In the new table style, I didn't define the alignment of the header row. That appears to have done it.

    Question: once you define part of a table style, like the header row being aligned centre, is there any way to remove that portion of the style? To make it as if you never set it at all? That seems to have made the difference.

    Friday, July 4, 2014 12:56 PM
  • You mean undo the changes of the table style? I don't think there's any way to do this. I recommend that you create a new one instead.

    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Tuesday, July 8, 2014 12:52 PM
    Moderator
  • <<Question: once you define part of a table style, like the header row being aligned centre, is there any way to remove that portion of the style? To make it as if you never set it at all? That seems to have made the difference.>>

    It could probably be done by modifying the Word Open XML, working directly with the file. You'd need to add the file exension .zip to the file name. Then you can see all the individual XML files that make up the document. There are separate XML file(s - depending on the version of Word involved) that define the styles and you should be able to change the definition directly.

    HOW you need to change it is the question, of course. My recommendation would be to compare a document where you've created a new style, the way you want it...


    Cindy Meister, VSTO/Word MVP, my blog

    Tuesday, July 8, 2014 7:04 PM
    Moderator