在下面的 MWE 中,有一个自定义箭头使用 定义为单独的绘图\tikz
。箭头用作边缘节点,以便可以自动倾斜。
我也在使用 TikZexternal
包,因为这是包含许多 TikZ 图形的一本书长度的项目的一部分。
梅威瑟:
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{external}
\tikzexternalize
\newcommand{\myarrow}{\tikz{\draw[->] (0,0)--(10pt,0)}}
\begin{document}
\begin{tikzpicture}
\node[draw] (1) at (0,0) {};
\node[draw] (2) at (1,1) {};
\draw (1) to[edge node={node [sloped,above] {\myarrow}}] (2);
\end{tikzpicture}
\end{document}
如果我尝试按原样编译 MWE,我会收到一条错误消息:
/mwe.tex:18: Package tikz Error: Sorry, the system call 'pdflatex -shell-escap
e -halt-on-error -interaction=batchmode -jobname "mwe-figure0" "\def\tikzextern
alrealjob{mwe}\input{mwe}"' did NOT result in a usable output file 'mwe-figure0
' (expected one of .pdf:.jpg:.jpeg:.png:). Please verify that you have enabled
system calls. For pdflatex, this is 'pdflatex -shell-escape'. Sometimes it is a
lso named 'write 18' or something like that. Or maybe the command simply failed
? Error messages can be found in 'mwe-figure0.log'. If you continue now, I'll t
ry to typeset the picture.
See the tikz package documentation for explanation.
Type H <return> for immediate help.
...
l.18 \end{tikzpicture}
?
[1{/usr/local/texlive/2021/texmf-var/fonts/map/pdftex/updmap/pdftex.map}]
(./mwe.aux) )</usr/local/texlive/2021/texmf-dist/fonts/type1/public/amsfonts/cm
/cmr10.pfb>
Output written on mwe.pdf (1 page, 8538 bytes).
SyncTeX written on mwe.synctex.gz.
Transcript written on mwe.log.
如果我注释掉该\tikzexternalize
行,它可以编译成功:
如果我注释掉该\draw (1) ...
行,它也能正常编译。有什么建议吗?
答案1
因为这不适合注释。已经指出不应嵌套tikzpicture
s。这也是没有必要的,Ti钾Z 有一个工具可以帮你完成这些工作:pic
s。这些也可以倾斜,并赋予参数(通过 pgf 键)。
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{external}
\tikzexternalize
\begin{document}
\begin{tikzpicture}[pics/my arrow/.style={code={
\tikzset{my arrow/.cd,#1}
\draw[my arrow/arrow]
(-\pgfkeysvalueof{/tikz/my arrow/length}/2,\pgfkeysvalueof{/tikz/my arrow/y})
--(\pgfkeysvalueof{/tikz/my arrow/length}/2,\pgfkeysvalueof{/tikz/my arrow/y});}},
my arrow/.cd,
arrow/.style={->},length/.initial=10pt,y/.initial={0pt}]
\node[draw] (1) at (0,0) {};
\node[draw] (2) at (1,1) {};
\draw (1) to pic[sloped]{my arrow={y=4pt}} (2);
\end{tikzpicture}
\end{document}