首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >无法使用pylatex放置图像

无法使用pylatex放置图像
EN

Stack Overflow用户
提问于 2021-11-23 13:21:11
回答 1查看 47关注 0票数 1

我正在使用pylatex创建一个pdf,其中包含我指定的坐标中的图像。我使用了下面的代码,但无论我输入什么坐标,图像总是在左上角。请帮帮我。

代码语言:javascript
复制
from pylatex import (Document, TikZ, 
                 TikZNode, TikZCoordinate, 
                 TikZOptions, StandAloneGraphic,  NoEscape)
       
geometry_options = {"margin": "0cm"}
doc = Document(documentclass='standalone',document_options=('tikz'), geometry_options=geometry_options)

doc.append(NoEscape(r'\noindent'))
    
with doc.create(TikZ()) as pic:
    
# img = TikZNode(text='\includegraphics[width=0.8\\textwidth]{example-image-a}',
#                         at = TikZCoordinate(3,4),
#                         options=TikZOptions('inner sep=0pt,anchor=south west'))

img = TikZNode(text=StandAloneGraphic('example-image-a').dumps(),
                at = TikZCoordinate(1,2),
                options=TikZOptions('inner sep=0pt')
                )

pic.append(img)

tex = doc.dumps()

doc.generate_pdf('basic',compiler='lualatex', clean_tex=False)
doc.generate_tex()

Tex-Code:

代码语言:javascript
复制
\documentclass[tikz]{standalone}%
\usepackage[T1]{fontenc}%
\usepackage[utf8]{inputenc}%
\usepackage{lmodern}%
\usepackage{textcomp}%
\usepackage{lastpage}%
\usepackage{geometry}%
\geometry{margin=0cm}%
\usepackage{tikz}%
%
%
%
\begin{document}%
\normalsize%
\noindent%
\begin{tikzpicture}%
\node[inner sep=0pt] at (1.0,2.0) {\includegraphics[width=0.8\textwidth]{example-image-a}};%
\end{tikzpicture}%
\end{document}

对我来说,这看起来与这篇文章中的代码非常相似:https://tex.stackexchange.com/questions/9559/drawing-on-an-image-with-tikz

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-11-23 14:01:24

tikz图片的大小将根据内容进行调整,它通常放在页面上使用它的任何位置,就像你写一封普通的信一样。

如果你在你的图片中添加另一个更大的元素,你可以看到这一点。如果现在使用节点的坐标,您将看到图像四处移动。

通常,您也可以使用[remember picture, overlay]选项相对于纸张定位节点,但您使用的是standalone类,该类将根据内容自动调整纸张大小,因此在您的情况下这没有帮助。

代码语言:javascript
复制
\documentclass[tikz]{standalone}%
\usepackage[T1]{fontenc}%
\usepackage[utf8]{inputenc}%
\usepackage{lmodern}%
\usepackage{textcomp}%
\usepackage{lastpage}%
%\usepackage{geometry}%
%\geometry{margin=0cm}%
\usepackage{tikz}%
%
%
%
\begin{document}%
\normalsize%
\noindent%
\begin{tikzpicture}%
\path (-20,-20) rectangle (20,20);
\node[inner sep=0pt] at (3.0,2.0) {\includegraphics[width=0.8\textwidth]{example-image-a}};%
\end{tikzpicture}%
\end{document}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/70081667

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档