none
Linked styles problem RRS feed

  • Question

  • Hi,

    In my docx file I tried to link a normal paragraph style and a character style together, but I got no luck.
    I used the following styles.xml:

    Code Block

       <w:styles xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main">
      <w:style w:type="paragraph" w:styleId="TestStyle1">
        <w:pPr>
          <w:ind w:left="500" w:right="500" />
          <w:spacing w:before="200" w:after="200" />
          <w:jc w:val="both" />
          <w:pBdr>
            <w:top w:val="dashed" />
            <w:left w:val="dashed" />
            <w:right w:val="dashed" />
            <w:bottom w:val="dashed" />
          </w:pBdr>
        </w:pPr>
        <w:rPr >
        </w:rPr >
        <w:link w:val="CharStyle1" />
      </w:style>
      <w:style w:type="character" w:styleId="CharStyle1">
        <w:rPr>
          <w:b />
        </w:rPr>
      </w:style>
    </w:styles>


    In the document.xml:

     
    Code Block

      <w:p>
          <w:pPr>
            <w:pStyle w:val="TestStyle1" />
          </w:pPr>
          <w:r>
            <w:rPr>
              <w:t xml:space="preserve">Lorem ipsum dolor sit amet

    </w:t>
            </w:rPr>
          </w:r>
        </w:p>



    As I learned, the linked character style would affect the run part of the paragraph stye when they get linked (in my case the text of my paragraph should be bold)
    I tried to link the paragraphstyle to the charstyle (as it used to be used) but the result was the same. What else should I set?
    Tuesday, November 27, 2007 12:07 AM

Answers

  •  

    Guys, I think you're not understanding linked styles completely. First of all, it is just a UI feature. You have two styles with the same name in the UI, so you have one button that the user can press, either for a piece of selected text (character style used), or when no text is selected (paragraph style used).

    The character style part is only applied when a small piece of text is selected, like usual for character styles. The paragraph style is only applied when the cursor is in a paragraph with no text selected, like usual for paragraph styles.

     

    So the following happens: (remember, there is only 1 button in the UI)

     

    - When the user selects a paragraph, and applies the linked style

         - word applies the paragraph and character properties from the paragraph style part of the linked style (the pPr and rPr nodes within <style type=paragraph>

     

    - When the user selects a text, and applies the linked style

        - word applies the character properties from the character style part of the linked (the rPr node within <style type=character>. E.g. Word does not touch the paragraph part of the linked style.

     

    Since the user expects both actions to result in similarly formatted text, both styles of a linked style usually consist of the same settings within the rPr property container.

     

    Hope it helps,

     

    Wouter

    Tuesday, December 4, 2007 1:48 PM

All replies

  • Hi,

     

    you need to link the character style back to the paragraph style using the similar <w:link> construct.

     

    Hope it helps,

     

    Wouter

    Sunday, December 2, 2007 1:03 PM


  • That doesn't solve the issue.
    Sunday, December 2, 2007 11:01 PM
  • I tried in WORD, it seems that you need to copy whatever defined in "character" style into the linked "paragraph" style to make it effect in WORD. This is not only for <w:b/> but also for <w:i/> etc.

    Monday, December 3, 2007 8:47 AM
  • I don't understand. If I have to define the character styling tags in the paragraph section as well, then why would I link the character style again?
    Monday, December 3, 2007 6:07 PM
  •  

    Guys, I think you're not understanding linked styles completely. First of all, it is just a UI feature. You have two styles with the same name in the UI, so you have one button that the user can press, either for a piece of selected text (character style used), or when no text is selected (paragraph style used).

    The character style part is only applied when a small piece of text is selected, like usual for character styles. The paragraph style is only applied when the cursor is in a paragraph with no text selected, like usual for paragraph styles.

     

    So the following happens: (remember, there is only 1 button in the UI)

     

    - When the user selects a paragraph, and applies the linked style

         - word applies the paragraph and character properties from the paragraph style part of the linked style (the pPr and rPr nodes within <style type=paragraph>

     

    - When the user selects a text, and applies the linked style

        - word applies the character properties from the character style part of the linked (the rPr node within <style type=character>. E.g. Word does not touch the paragraph part of the linked style.

     

    Since the user expects both actions to result in similarly formatted text, both styles of a linked style usually consist of the same settings within the rPr property container.

     

    Hope it helps,

     

    Wouter

    Tuesday, December 4, 2007 1:48 PM
  • I get it.

    I thought it works as I described below:

    I imagine the linked styles as I can spare lots of unnecessary nodes. I create a paragraph style, and I link it to a character style (which is a separate style so it can be used to format text), so the text of the paragraph is formatted by the linked character style.

    What you wrote, I imagine such way (pseudo):

    Code Block

    <style t=paragraph n="par1">

    <link name="charstyle"/>

    <pPr>
    <centered>
    <ind=100>
    </pPr>
    <rPr>
    <bold/><color yellow/>

    </rPr>

    </style>




    <style t=char n="charstyle">

    <rPr>
    <bold/><color yellow/>

    </rPr>

    </style>


    It is clear, I didn't spare any character, I wrote the char style twice. Instead it would be more efficient:

    Code Block

      

    <style t=paragraph n="par1">

    <link name="charstyle"/>

    <pPr>
    <centered>
    <ind=100>

    </style>

     


    <style t=char n="charstyle">

    <rPr>
    <bold/><color yellow/>

    </rPr>

    </style>



    The second way is what I look for. When I define a paragraph with the style, it'd apply the paragraph properties then for the runs inside it would apply the linked character style (and as I mentioned, the character style could be used by any other runs).
    It would be nice, if it can be used like that.
    If I misinterpreted your answer, please correct me. My English is very poor, I might have understood it wrongly.

    But it is clear now. Thanks.
    Thursday, December 6, 2007 9:54 PM