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}

여기에 이미지 설명을 입력하세요

관련 정보