|
| 1 | + |
| 2 | +Paragraph alignment |
| 3 | +=================== |
| 4 | + |
| 5 | +In Word, each paragraph has an *alignment* attribute that specifies how to |
| 6 | +justify the lines of the paragraph when the paragraph is laid out on the |
| 7 | +page. Common values are left, right, centered, and justified. |
| 8 | + |
| 9 | + |
| 10 | +Protocol |
| 11 | +-------- |
| 12 | + |
| 13 | +The protocol for getting and setting paragraph alignment is illustrated in |
| 14 | +this interactive session:: |
| 15 | + |
| 16 | + >>> paragraph = body.add_paragraph() |
| 17 | + >>> paragraph.alignment |
| 18 | + None |
| 19 | + >>> paragraph.alignment = WD_ALIGN_PARAGRAPH.RIGHT |
| 20 | + >>> paragraph.alignment |
| 21 | + RIGHT (2) |
| 22 | + >>> paragraph.alignment = None |
| 23 | + >>> paragraph.alignment |
| 24 | + None |
| 25 | + |
| 26 | + |
| 27 | +Semantics |
| 28 | +--------- |
| 29 | + |
| 30 | +If the ``<w:jc>`` element is not present on a paragraph, the alignment value |
| 31 | +for that paragraph is inherited from its style hierarchy. If the element is |
| 32 | +present, its value overrides any inherited value. From the API, a value of |
| 33 | +|None| on the ``Paragraph.alignment`` property corresponds to no ``<w:jc>`` |
| 34 | +element being present. If |None| is assigned to ``Paragraph.alignment``, the |
| 35 | +``<w:jc>`` element is removed. |
| 36 | + |
| 37 | + |
| 38 | +Enumerations |
| 39 | +------------ |
| 40 | + |
| 41 | +WD_ALIGN_PARAGRAPH |
| 42 | +~~~~~~~~~~~~~~~~~~ |
| 43 | + |
| 44 | +`WdParagraphAlignment Enumeration on MSDN`_ |
| 45 | + |
| 46 | ++--------------+------+----------------+ |
| 47 | +| Name | enum | attr | |
| 48 | ++==============+======+================+ |
| 49 | +| LEFT | 0 | left | |
| 50 | ++--------------+------+----------------+ |
| 51 | +| CENTER | 1 | center | |
| 52 | ++--------------+------+----------------+ |
| 53 | +| RIGHT | 2 | right | |
| 54 | ++--------------+------+----------------+ |
| 55 | +| JUSTIFY | 3 | both | |
| 56 | ++--------------+------+----------------+ |
| 57 | +| DISTRIBUTE | 4 | distribute | |
| 58 | ++--------------+------+----------------+ |
| 59 | +| JUSTIFY_MED | 5 | mediumKashida | |
| 60 | ++--------------+------+----------------+ |
| 61 | +| JUSTIFY_HI | 7 | highKashida | |
| 62 | ++--------------+------+----------------+ |
| 63 | +| JUSTIFY_LOW | 8 | lowKashida | |
| 64 | ++--------------+------+----------------+ |
| 65 | +| THAI_JUSTIFY | 9 | thaiDistribute | |
| 66 | ++--------------+------+----------------+ |
| 67 | + |
| 68 | +.. _WdParagraphAlignment Enumeration on MSDN: |
| 69 | + http://msdn.microsoft.com/en-us/library/office/ff835817(v=office.15).aspx |
| 70 | + |
| 71 | + |
| 72 | +Specimen XML |
| 73 | +------------ |
| 74 | + |
| 75 | +.. highlight:: xml |
| 76 | + |
| 77 | +A paragraph with inherited alignment:: |
| 78 | + |
| 79 | + <w:p> |
| 80 | + <w:r> |
| 81 | + <w:t>Inherited paragraph alignment.</w:t> |
| 82 | + </w:r> |
| 83 | + </w:p> |
| 84 | + |
| 85 | +A right-aligned paragraph:: |
| 86 | + |
| 87 | + <w:p> |
| 88 | + <w:pPr> |
| 89 | + <w:jc w:val="right"/> |
| 90 | + </w:pPr> |
| 91 | + <w:r> |
| 92 | + <w:t>Right-aligned paragraph.</w:t> |
| 93 | + </w:r> |
| 94 | + </w:p> |
| 95 | + |
| 96 | + |
| 97 | +Schema excerpt |
| 98 | +-------------- |
| 99 | + |
| 100 | +:: |
| 101 | + |
| 102 | + <xsd:complexType name="CT_P"> |
| 103 | + <xsd:sequence> |
| 104 | + <xsd:element name="pPr" type="CT_PPr" minOccurs="0"/> |
| 105 | + <xsd:group ref="EG_PContent" minOccurs="0" maxOccurs="unbounded"/> |
| 106 | + </xsd:sequence> |
| 107 | + <xsd:attribute name="rsidRPr" type="ST_LongHexNumber"/> |
| 108 | + <xsd:attribute name="rsidR" type="ST_LongHexNumber"/> |
| 109 | + <xsd:attribute name="rsidDel" type="ST_LongHexNumber"/> |
| 110 | + <xsd:attribute name="rsidP" type="ST_LongHexNumber"/> |
| 111 | + <xsd:attribute name="rsidRDefault" type="ST_LongHexNumber"/> |
| 112 | + </xsd:complexType> |
| 113 | + |
| 114 | + <xsd:complexType name="CT_PPr"> <!-- denormalized --> |
| 115 | + <xsd:sequence> |
| 116 | + <xsd:element name="pStyle" type="CT_String" minOccurs="0"/> |
| 117 | + <xsd:element name="keepNext" type="CT_OnOff" minOccurs="0"/> |
| 118 | + <xsd:element name="keepLines" type="CT_OnOff" minOccurs="0"/> |
| 119 | + <xsd:element name="pageBreakBefore" type="CT_OnOff" minOccurs="0"/> |
| 120 | + <xsd:element name="framePr" type="CT_FramePr" minOccurs="0"/> |
| 121 | + <xsd:element name="widowControl" type="CT_OnOff" minOccurs="0"/> |
| 122 | + <xsd:element name="numPr" type="CT_NumPr" minOccurs="0"/> |
| 123 | + <xsd:element name="suppressLineNumbers" type="CT_OnOff" minOccurs="0"/> |
| 124 | + <xsd:element name="pBdr" type="CT_PBdr" minOccurs="0"/> |
| 125 | + <xsd:element name="shd" type="CT_Shd" minOccurs="0"/> |
| 126 | + <xsd:element name="tabs" type="CT_Tabs" minOccurs="0"/> |
| 127 | + <xsd:element name="suppressAutoHyphens" type="CT_OnOff" minOccurs="0"/> |
| 128 | + <xsd:element name="kinsoku" type="CT_OnOff" minOccurs="0"/> |
| 129 | + <xsd:element name="wordWrap" type="CT_OnOff" minOccurs="0"/> |
| 130 | + <xsd:element name="overflowPunct" type="CT_OnOff" minOccurs="0"/> |
| 131 | + <xsd:element name="topLinePunct" type="CT_OnOff" minOccurs="0"/> |
| 132 | + <xsd:element name="autoSpaceDE" type="CT_OnOff" minOccurs="0"/> |
| 133 | + <xsd:element name="autoSpaceDN" type="CT_OnOff" minOccurs="0"/> |
| 134 | + <xsd:element name="bidi" type="CT_OnOff" minOccurs="0"/> |
| 135 | + <xsd:element name="adjustRightInd" type="CT_OnOff" minOccurs="0"/> |
| 136 | + <xsd:element name="snapToGrid" type="CT_OnOff" minOccurs="0"/> |
| 137 | + <xsd:element name="spacing" type="CT_Spacing" minOccurs="0"/> |
| 138 | + <xsd:element name="ind" type="CT_Ind" minOccurs="0"/> |
| 139 | + <xsd:element name="contextualSpacing" type="CT_OnOff" minOccurs="0"/> |
| 140 | + <xsd:element name="mirrorIndents" type="CT_OnOff" minOccurs="0"/> |
| 141 | + <xsd:element name="suppressOverlap" type="CT_OnOff" minOccurs="0"/> |
| 142 | + <xsd:element name="jc" type="CT_Jc" minOccurs="0"/> |
| 143 | + <xsd:element name="textDirection" type="CT_TextDirection" minOccurs="0"/> |
| 144 | + <xsd:element name="textAlignment" type="CT_TextAlignment" minOccurs="0"/> |
| 145 | + <xsd:element name="textboxTightWrap" type="CT_TextboxTightWrap" minOccurs="0"/> |
| 146 | + <xsd:element name="outlineLvl" type="CT_DecimalNumber" minOccurs="0"/> |
| 147 | + <xsd:element name="divId" type="CT_DecimalNumber" minOccurs="0"/> |
| 148 | + <xsd:element name="cnfStyle" type="CT_Cnf" minOccurs="0"/> |
| 149 | + <xsd:element name="rPr" type="CT_ParaRPr" minOccurs="0"/> |
| 150 | + <xsd:element name="sectPr" type="CT_SectPr" minOccurs="0"/> |
| 151 | + <xsd:element name="pPrChange" type="CT_PPrChange" minOccurs="0"/> |
| 152 | + </xsd:sequence> |
| 153 | + </xsd:complexType> |
| 154 | + |
| 155 | + <xsd:complexType name="CT_Jc"> |
| 156 | + <xsd:attribute name="val" type="ST_Jc" use="required"/> |
| 157 | + </xsd:complexType> |
| 158 | + |
| 159 | + <xsd:simpleType name="ST_Jc"> |
| 160 | + <xsd:restriction base="xsd:string"> |
| 161 | + <xsd:enumeration value="start"/> |
| 162 | + <xsd:enumeration value="center"/> |
| 163 | + <xsd:enumeration value="end"/> |
| 164 | + <xsd:enumeration value="both"/> |
| 165 | + <xsd:enumeration value="mediumKashida"/> |
| 166 | + <xsd:enumeration value="distribute"/> |
| 167 | + <xsd:enumeration value="numTab"/> |
| 168 | + <xsd:enumeration value="highKashida"/> |
| 169 | + <xsd:enumeration value="lowKashida"/> |
| 170 | + <xsd:enumeration value="thaiDistribute"/> |
| 171 | + <xsd:enumeration value="left"/> |
| 172 | + <xsd:enumeration value="right"/> |
| 173 | + </xsd:restriction> |
| 174 | + </xsd:simpleType> |
0 commit comments