PyX — Example: text/halign.py
Horizontal alignment
from pyx import * c = canvas.canvas() c.stroke(path.line(-5, 0, -5, 5)) c.stroke(path.line(0, 0, 0, 5)) c.stroke(path.line(5, 0, 5, 5)) c.text(-5, 5, r"boxleft", [text.halign.boxleft]) c.text(0, 5, r"boxcenter", [text.halign.boxcenter]) c.text(5, 5, r"boxright", [text.halign.boxright]) c.text(0, 4, r"boxcenter and flushleft", [text.parbox(3), text.halign.boxcenter, text.halign.flushleft]) c.text(0, 3, r"boxcenter and flushcenter", [text.parbox(3), text.halign.boxcenter, text.halign.flushcenter]) c.text(0, 2, r"boxcenter and flushright", [text.parbox(3), text.halign.boxcenter, text.halign.flushright]) c.text(-5, 0, r"left: boxleft and flushleft", [text.parbox(3), text.halign.left]) c.text(0, 0, r"center: boxcenter and flushcenter", [text.parbox(3), text.halign.center]) c.text(5, 0, r"right: boxright and flushright", [text.parbox(3), text.halign.right]) c.writeEPSfile("halign") c.writePDFfile("halign") c.writeSVGfile("halign")
Description
The example shows the result of the different text attributes for horizontal alignment. We first need to emphasize, that PyX distinguishes between the alignment of the text box and the alignment of the material within the text box. The first line in the output shows the effect of the box alignment created by boxleft
, boxcenter
and boxright
leading to left, center, and right alignment of the text box with respect to the dotted lines.
The middle part shows the examples for centering a box, but aligning the content differently inside the box, namely at the left box boundary by flushleft
, at the center by flushcenter
and at the right box boundary by flushright
. Note, that such an alignment of material is available only when you create a parbox in TeX. This is easily done by means of the parbox
attribute, where you have to specify the width of the box.
At the bottom, you can see combinations of boxleft
and flushleft
, boxcenter
and flushcenter
, and boxright
and boxcenter
in action. These combinations are available by the attributes left
, center
and right
to shortcut the setting of both corresponding attributes. You can use these shortcuts for box alignment as well, when you do not create a parbox.
Note that the alignment features are implemented in such a way, that they work in both, TeX and LaTeX mode. Furthermore, you can always influence the alignment of the box contents by appropriate TeX and LaTeX commands as well.