foreach ループの現在の値を使用して、描画されるオブジェクトの幅を変更するにはどうすればよいですか?

foreach ループの現在の値を使用して、描画されるオブジェクトの幅を変更するにはどうすればよいですか?

Tiを作成したい数値のベクトルを使用して画像を含めるZプロット。現在の値を使用して画像を拡大縮小し、値の高い画像がy-axis低い値の画像よりも大きくなるようにしたいのですが、なぜか常にエラーが発生します。「測定単位が正しくありません (pt が挿入されました)」幅引数で変数を使用しようとしたとき。これまで私が行ったことは次のとおりです。

\begin{tikzpicture}
\foreach \y [count=\x] in {0.5, 0.7, 0.8, 0.9, 0.95, 1, 1.05, 1.07, 1.2, 1.205, 2, 3, 3.1, 5, 5.4, 5.8, 6.1, 6.15, 6.125, 6.4}
\node at(\x,\y) {\includegraphics[width=\y*0.2cm]{../figs/Potato.png}};
\end{tikzpicture}

答え1

\includegraphicspgf とは異なり、キーの引数を解析しないため、解析する必要があります。

\documentclass[tikz,border=3mm]{standalone}
\begin{document}
\begin{tikzpicture}
\foreach \y [count=\x] in {0.5, 0.7, 0.8, 0.9, 0.95, 1, 1.05, 1.07, 1.2, 1.205, 2, 3, 3.1, 5, 5.4, 5.8, 6.1, 6.15, 6.125, 6.4}
\node at(\x,\y) {\pgfmathparse{\y*0.2}\includegraphics[width=\pgfmathresult cm]{example-image-duck}};
\end{tikzpicture}
\end{document}

ここに画像の説明を入力してください

ところで、\x図書館\yでも使われていますcalc。だから私は個人的には

\documentclass[tikz,border=3mm]{standalone}
\begin{document}
\begin{tikzpicture}
\foreach \Y [count=\X] in {0.5, 0.7, 0.8, 0.9, 0.95, 1, 1.05, 1.07, 1.2, 1.205, 2, 3, 3.1, 5, 5.4, 5.8, 6.1, 6.15, 6.125, 6.4}
\node at(\X,\Y) {\pgfmathparse{\Y*0.2}\includegraphics[width=\pgfmathresult cm]{example-image-duck}};
\end{tikzpicture}
\end{document}

calc後でループ内で使用することにした場合に備えて、安全を確保します。

答え2

foreachループで計算を進めて回避することが可能です\pgfmathparse

\documentclass[tikz,border=3mm]{standalone}
\begin{document}
\begin{tikzpicture}
\foreach \y [count=\x, evaluate=\y as \width using \y*0.2] in {0.5, 0.7, 0.8, 0.9, 0.95, 1, 1.05, 1.07, 1.2, 1.205, 2, 3, 3.1, 5, 5.4, 5.8, 6.1, 6.15, 6.125, 6.4}
\node at(\x,\y) {\includegraphics[width=\width cm]{example-image}};
\end{tikzpicture}
\end{document}

ここに画像の説明を入力してください

関連情報