Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extend tikz node at #324

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 53 additions & 0 deletions examples/tikzcp.py
Original file line number Diff line number Diff line change
@@ -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)
10 changes: 5 additions & 5 deletions pylatex/tikz.py
Original file line number Diff line number Diff line change
Expand Up @@ -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', 'north east', 'south east', 'south west', 'north west']

def __init__(self, handle=None, options=None, at=None, text=None):
"""
Expand All @@ -209,21 +209,21 @@ 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
"""
super(TikZNode, self).__init__(options=options)

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

Expand Down