How to add margins to table cell?

Feb 5, 2011 at 10:40 AM

Hi!

First of all, I'd like to thank you for the wonderful BibWord!

I'm currently using the AMA style for writing my PhD.

I was wondering if it's possible define some additional left margin in the second table cell (column).

I know it can be done directly in Word but every time I update my bibliography, the margin disappears.
So maybe it's possible to define such a margin in the XLX template (?)

Thank you for all advices.

Regards,
drProzac

Coordinator
Feb 9, 2011 at 8:31 AM

Look for the following line of code:

<td align="{$params/bibliography/source[@type = $type]/column[@id = $columnId]/halign}" valign="{$params/bibliography/source[@type = $type]/column[@id = $columnId]/valign}">

Here you could add margins. Note that this line is repeated for every column, so you might have to redesign this part a little if you only want the margins in the second column.

An idea could be to add a variable just above and then use that. Something along the lines

<xsl:variable name="localStyle">
  <column id="1"></column>
  <column id="2">margin-left: 5em;</column>
</xskl:variable>

Then in the line at the top, you could add

  style="{$localStyle/column[@id = $columnId]}"

(This is untested code)

Mar 7, 2011 at 5:10 PM

Thank you very much for your reply.

I tried to implement your solution but when I modified the XSL file the style disappeared from the style list so I guess Word detected something wrong and did not load the template.

I'd be very thankful if you could give me some more advices.

Regards,
Prozac

Coordinator
Mar 8, 2011 at 5:53 PM

If the XSL is not well-formatted, Word won't execute it.

Probably easier. Change

<td align="{$params/bibliography/source[@type = $type]/column[@id = $columnId]/halign}" valign="{$params/bibliography/source[@type = $type]/column[@id = $columnId]/valign}">

into

<td align="{$params/bibliography/source[@type = $type]/column[@id = $columnId]/halign}" valign="{$params/bibliography/source[@type = $type]/column[@id = $columnId]/valign}" style="{$params/bibliography/source[@type = $type]/column[@id = $columnId]/style}">

And then add "style" elements to every column element in the data section you want the extra margin (or something else). So e.g.:

      <source type="Book">
        <column id="1">
          <halign>right</halign>
          <valign>top</valign>
          <format>%RefOrder%.</format>
        </column>
        <column id="2">
          <halign>left</halign>
          <valign>top</valign>
          <format>{%Author:0|Editor:1%}{. &lt;i&gt;%Title|ShortTitle%&lt;/i&gt;}{. Vol %Volume%}{. %Edition% ed}{. %City%}{: %Publisher%}{; %Year%}.</format>
        </column>
        <sortkey></sortkey>
      </source>

would become

      <source type="Book">
        <column id="1">
          <halign>right</halign>
          <valign>top</valign>
          <format>%RefOrder%.</format>
        </column>
        <column id="2">
          <halign>left</halign>
          <valign>top</valign>
          <style>margin-left: 10em;</style>
          <format>{%Author:0|Editor:1%}{. &lt;i&gt;%Title|ShortTitle%&lt;/i&gt;}{. Vol %Volume%}{. %Edition% ed}{. %City%}{: %Publisher%}{; %Year%}.</format>
        </column>
        <sortkey></sortkey>
      </source>
Mar 8, 2011 at 6:22 PM

Thank you very much for the detailed explanation!
This one works as expected :-)

I've just came across another problem.
I mean, very often bibliography items are divided  between pages. Some part of the item remains on one page and the rest (volume, page numbers) are brought forward to the next page.
This is because the "Allow row to break across pages" in the table properties is enabled.
Do you think it may be possible to disable this option via the XLS script?

Regards,
Prozac

Coordinator
Mar 8, 2011 at 8:18 PM

Try replacing

        <tr>
          <xsl:call-template name="format-bibliography-table-column">
            <xsl:with-param name="columnId" select="1"/>
            <xsl:with-param name="source" select="."/>
          </xsl:call-template>
        </tr>

with 

        <tr style="page-break-inside:avoid">
          <xsl:call-template name="format-bibliography-table-column">
            <xsl:with-param name="columnId" select="1"/>
            <xsl:with-param name="source" select="."/>
          </xsl:call-template>
        </tr>

This will give the behaviour you want, but I'm not sure Word is able to handle it well. I think I left this out originally because during tests ghosts of rows were showing up.

Mar 8, 2011 at 11:32 PM

Yes! It works perfectly. I'm working with Word 2007 and seems it interpreted the style correctly :) The option "Allow row to break across pages" is now disabled and I haven't noticed any empty rows or incorrect lines.

I have one more question but I will create a new thread since it has nothing to do with table cells.

Once again, thanks for the wonderful support.

Mar 9, 2011 at 10:48 PM

You helped me to implement some additional margin for the text of the 2nd column and you also helped me to disable page-breaks inside rows.
My bibliography is almost perfect :-)

I was just wondering if it's possible to change the default cell margins of the bibliography table
http://www.avirecomp.com/mateo/images/screenshots/word_table_prop_options.png

They are always set to 0.03 cm by default and I'd like to remove all of them and also to disable spacing.

Coordinator
Mar 10, 2011 at 6:32 AM

It takes over your default Word table settings. You could hard-code others inside the xsl. Just change the line

<table width="100%">

into

<table width="100%" border="0" cellspacing="0" cellpadding="0">

and there should be no padding or spacing in your table.

Mar 10, 2011 at 7:02 PM

Thanks a lot!

BTW, I'm not a HTML expert but in your second post you advised me to use margin-left to increase the left margin of the text in the second column.
I wonder if I could reach the same effect by adding the padding-left property to the td element?

BTW 2 :-)
I was trying to insert a  code snippet but seems it doesn't want to work with Opera. I tried to use Chrome and it works fine.
Take a look at the screenie: http://www.avirecomp.com/mateo/images/screenshots/bibword_code.png
The same happens with the HTML option.

 

Coordinator
Mar 10, 2011 at 8:48 PM

Assuming Word's html converter understands padding-left correctly, that would indeed work.

Mar 10, 2011 at 9:15 PM

I tried to replace margin-left with padding-left and got exactly the same effect.
Strange, because they have two different meanings.