Tab Stops ========= WordprocessingML allows for custom specification of tab stops at the paragraph level. Tab stop spacing is a subset of paragraph formatting in this system, so will be implemented within the docx.text.parfmt.ParagraphFormatting object. Tab stops will be handled as a List-like TabStops object made up of TabStop objects. A TabStop object has three properties, alignment, leader, and position. Alignment is a WD_TAB_ALIGNMENT member and position is a Length() object. Tab stops are always sorted in position order. Alignment defaults to WD_TAB_ALIGNMENT.LEFT, and leader defaults to WD_TAB_LEADER.SPACES. Tab stops specify how tab characters in a paragraph are rendered. Insertion of tab characters is accomplished using the Run object. Protocol -------- .. highlight:: python Getting and setting tab stops:: >>> tab_stops = paragraph.paragraph_format.tab_stops >>> tab_stops >>> tab_stop = tab_stops.add_tab_stop(Inches(2), WD_TAB_ALIGNMENT.LEFT, WD_TAB_LEADER.DOTS) # add_tab_stop defaults to WD_TAB_ALIGNMENT.LEFT, WD_TAB_LEADER.SPACES >>> tab_stop = tab_stops.add_tab_stop(Inches(0.5)) >>> tab_stop.alignment WD_TAB_ALIGNMENT.LEFT >>> tab_stop.leader WD_TAB_LEADER.SPACES # TabStop properties are read/write >>> tab_stop.position = Inches(2.5) >>> tab_stop.alignment = WD_TAB_ALIGNMENT.CENTER >>> tab_stop.leader = WD_TAB_LEADER.DASHES # Tab stops are sorted into position order as created or modified >>> [(t.position, t.alignment) for t in tab_stops] [(914400, WD_TAB_ALIGNMENT.LEFT), (2286000, WD_TAB_ALIGNMENT.CENTER)] # A tab stop is deleted using del statement >>> len(tab_stops) 2 >>> del tab_stops[1] >>> len(tab_stops) 1 # Restore default tabs >>> tab_stops.clear() Word Behavior ------------- When the w:tabs element is empty or not present, Word uses default tab stops (typically every half inch). Word resumes using default tab stops following the last specified tab stop. TabStops must be in position order within the XML. If they are not, the out- of-order tab stop will appear in the ruler and in the properties dialog, but will not actually be used by Word. XML Semantics ------------- * Both "num" and "list" alignment are a legacy from early versions of Word before hanging indents were available. Both are deprecated. * "start" alignment is equivalent to "left", and "end" alignment are equivalent to "right". (Confirmed with manually edited XML.) * A "clear" tab stop is not shown in Word's tab bar and default tab behavior is followed in the document. That is, Word ignores that tab stop specification completely, acting as if it were not there at all. This allows a tab stop inherited from a style, for example, to be ignored. * The w:pos attribute uses twips rather than EMU. * The w:tabs element must be removed when empty. If present, it must contain at least one w:tab element. Specimen XML ------------ .. highlight:: xml :: Enumerations ------------ * `WdTabAlignment Enumeration on MSDN`_ .. _WdTabAlignment Enumeration on MSDN: https://msdn.microsoft.com/EN-US/library/office/ff195609.aspx ================= ======== ===== Name XML Value ================= ======== ===== wdAlignTabBar bar 4 wdAlignTabCenter center 1 wdAlignTabDecimal decimal 3 wdAlignTabLeft left 0 wdAlignTabList list 6 wdAlignTabRight right 2 ================= ======== ===== Additional Enumeration values not appearing in WdTabAlignment =============== ======== ===== Name XML Value =============== ======== ===== wdAlignTabClear clear 101 wdAlignTabEnd end 102 wdAlignTabNum num 103 wdAlignTabStart start 104 =============== ======== ===== * `WdTabLeader Enumeration on MSDN`_ .. _WdTabLeader Enumeration on MSDN: https://msdn.microsoft.com/en-us/library/office/ff845050.aspx ==================== ========== ===== Name XML Value ==================== ========== ===== wdTabLeaderDashes hyphen 2 wdTabLeaderDots dot 1 wdTabLeaderHeavy heavy 4 wdTabLeaderLines underscore 3 wdTabLeaderMiddleDot middleDot 5 wdTabLeaderSpaces none 0 ==================== ========== ===== MS API Protocol --------------- The MS API defines a `TabStops object`_ which is a collection of `TabStop objects`_. .. _TabStops object: https://msdn.microsoft.com/EN-US/library/office/ff192806.aspx .. _TabStop objects: https://msdn.microsoft.com/EN-US/library/office/ff195736.aspx Schema excerpt -------------- ::