我想这样做:
但用可变的宽度书写:
\documentclass[tikz,border=5mm]{standalone}
\begin{document}
\def\mywidth{2cm}
\tikz\node[circle,draw,minimum size=1.2*\mywidth
text=white,
path picture={
\node at (path picture bounding box.center){
\includegraphics[width=1.2\mywidth]{frog}
};
}]{I'm watching you!};
\end{document}
为什么这不起作用?该includegraphics
命令不显示图像,1.2\mywidth
而是显示任意大小。圆圈大小正确。
第二个例子
代码 1
\documentclass[tikz,border=5mm]{standalone}
\begin{document}
\def\firstwidth{1cm}
\def\secondwidth{2\firstwidth}
\tikz\node[circle,draw,minimum size=\firstwidth,
path picture={
\node at (path picture bounding box.center){
\includegraphics[width=\firstwidth]{blackbox.png}
};
}]{};
\end{document}
结果 1
代码 2
\documentclass[tikz,border=5mm]{standalone}
\begin{document}
\def\firstwidth{1cm}
\def\secondwidth{2\firstwidth}
\tikz\node[circle,draw,minimum size=\firstwidth,
path picture={
\node at (path picture bounding box.center){
\includegraphics[width=0.5\secondwidth]{blackbox.png}
};
}]{};
\end{document}
结果 2(应与结果 1 类似)
答案1
问题似乎是如何定义长度\mywidth
、\firstwidth
和\secondwidth
。如果使用\def\mywidth{2cm}
定义,而不是等:
\newlength\mywidth\setlength\mywidth{2cm}
\newlength\firstwidth
\setlength\firstwidth{1cm}
\newlength\secondwidth
\setlength\secondwidth{2\firstwidth}
您的示例将按预期工作(当然,如果我正确理解了您的问题):
完整的 MWE 是:
\documentclass[tikz,border=5mm]{standalone}
\usepackage{graphicx}
\begin{document}
\newlength\mywidth\setlength\mywidth{2cm}
\newlength\firstwidth
\setlength\firstwidth{1cm}
\newlength\secondwidth
\setlength\secondwidth{2\firstwidth}
\tikz\node[circle,draw,minimum size=1.2\mywidth,
text=white,
path picture={
\node at (path picture bounding box.center){
\includegraphics[width=1.2\mywidth]{example-image-a}
};
}]{see};
\tikz\node[circle,draw,minimum size=\firstwidth,
text=white,
path picture={
\node at (path picture bounding box.center){
\includegraphics[width=\firstwidth]{example-image-b}
};
}]{see};
\tikz\node[circle,draw,minimum size=\firstwidth,
text=white,
path picture={
\node at (path picture bounding box.center){
\includegraphics[width=0.5\secondwidth]{example-image-c}
};
}]{see};
\end{document}