From abbfee5804dde741169cd0f454eece4acaa66326 Mon Sep 17 00:00:00 2001 From: Antonio Cervone Date: Fri, 2 Apr 2021 10:13:21 +0200 Subject: [PATCH 1/3] Let TikZNode.at be also a TikZNodeAnchor --- pylatex/tikz.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/pylatex/tikz.py b/pylatex/tikz.py index 98add4be..fdf81860 100644 --- a/pylatex/tikz.py +++ b/pylatex/tikz.py @@ -199,7 +199,7 @@ def dumps(self): class TikZNode(TikZObject): """A class that represents a TiKZ node.""" - _possible_anchors = ['north', 'south', 'east', 'west'] + _possible_anchors = ['center', 'north', 'south', 'east', 'west'] def __init__(self, handle=None, options=None, at=None, text=None): """ @@ -209,8 +209,8 @@ def __init__(self, handle=None, options=None, at=None, text=None): Node identifier options: list List of options - at: TikZCoordinate - Coordinate where node is placed + at: TikZCoordinate of TikZNodeAnchor + Coordinate or anchor where node is placed text: str Body text of the node """ @@ -218,12 +218,12 @@ def __init__(self, handle=None, options=None, at=None, text=None): self.handle = handle - if isinstance(at, (TikZCoordinate, type(None))): + if isinstance(at, (TikZCoordinate, TikZNodeAnchor, type(None))): self._node_position = at else: raise TypeError( 'at parameter must be an object of the' - 'TikzCoordinate class') + 'TikZCoordinate or TikZNodeAnchor class') self._node_text = text From 5bdfa804fffa4ba23667e4f2af7535b9fe4a8f47 Mon Sep 17 00:00:00 2001 From: Antonio Cervone Date: Fri, 2 Apr 2021 11:14:12 +0200 Subject: [PATCH 2/3] add example that leverages TikZNode.at with anchor --- examples/tikzcp.py | 53 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 examples/tikzcp.py diff --git a/examples/tikzcp.py b/examples/tikzcp.py new file mode 100644 index 00000000..3623c6f6 --- /dev/null +++ b/examples/tikzcp.py @@ -0,0 +1,53 @@ +#!/usr/bin/python +""" +This example shows TikZ drawing capabilities overlaying the current page. + +.. :copyright: (c) 2021 by Antonio Cervone + :license: MIT, see License for more details. +""" + +# begin-doc-include +from pylatex import ( + Document, + TikZ, + TikZNode, + TikZNodeAnchor, + TikZOptions, +) + +if __name__ == "__main__": + + # create document + doc = Document() + + # options for the tikzpicture environment + tikz_opts = TikZOptions("remember picture", "overlay") + + # add our sample drawings + with doc.create(TikZ(options=tikz_opts)) as pic: + + # create an anchor to the page center + page_center = TikZNodeAnchor("current page", "center") + + # create a node on the center of the page + centerbox = TikZNode( + text="this is the center", + at=page_center, + options=TikZOptions("draw"), + ) + + # add to tikzpicture + pic.append(centerbox) + + # create an anchor to the page center + page_top = TikZNodeAnchor("current page", "north") + + # create a node at the top of the page + topbox = TikZNode( + text="this is the top", at=page_top, options=({"anchor": "north"}) + ) + + # add to tikzpicture + pic.append(topbox) + + doc.generate_pdf("tikzcp", clean_tex=False) From 497f14b87bcacd5c05c53a47f50665b9b7da02eb Mon Sep 17 00:00:00 2001 From: Antonio Cervone Date: Wed, 16 Jun 2021 11:42:06 +0200 Subject: [PATCH 3/3] add additional anchors --- pylatex/tikz.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pylatex/tikz.py b/pylatex/tikz.py index fdf81860..ef1656c4 100644 --- a/pylatex/tikz.py +++ b/pylatex/tikz.py @@ -199,7 +199,7 @@ def dumps(self): class TikZNode(TikZObject): """A class that represents a TiKZ node.""" - _possible_anchors = ['center', 'north', 'south', 'east', 'west'] + _possible_anchors = ['center', 'north', 'south', 'east', 'west', 'north east', 'south east', 'south west', 'north west'] def __init__(self, handle=None, options=None, at=None, text=None): """