TiKz 패키지: 함수 도메인 범위 맵에서 점을 숫자로 바꾸는 방법

TiKz 패키지: 함수 도메인 범위 맵에서 점을 숫자로 바꾸는 방법

원 안의 점을 숫자 값(1, 2, 3 등)으로 바꾸는 방법을 찾으려고 합니다.

이 교체를 수행하기 위해 편집해야 하는 코드 줄을 식별하는 데 도움을 주십시오.

미리 감사드립니다!

mwe(h/t 페쿠스)

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{shapes.geometric,fit}
\begin{document}
\begin{tikzpicture}
%put some nodes on the left
\foreach \x in {1,2,3}{
\node[fill,circle,inner sep=2pt] (d\x) at (0,\x) {};
}
\node[fit=(d1) (d2) (d3),ellipse,draw,minimum width=1cm] {}; 
%put some nodes on the center
\foreach \x[count=\xi] in {0.5,1.5,...,4}{
\node[fill,circle,inner sep=2pt] (r\xi) at (2,\x) {};
}
\node[fit=(r1) (r2) (r3) (r4),ellipse,draw,minimum width=1.5cm] {}; 
%put some nodes on the right
\foreach \x[count=\xi] in {0.75,1.5,...,3}{
\node[fill,circle,inner sep=2pt] (c\xi) at (4,\x) {};
}
\node[fit=(c1) (c2) (c3) (c4) ,ellipse,draw,minimum width=1.5cm] {};
\draw[-latex] (d1) -- (r2);
\draw[-latex] (d2) -- (r2);
\draw[-latex] (d3) -- (r4);
\draw[-latex] (r1) -- (c2);
\draw[-latex] (r2) -- (c3);
\draw[-latex] (d3) -- (r4);
\end{tikzpicture}
\end{document}

답변1

어떤 숫자를 어디에 배치하고 싶은지 모르겠지만 일반적으로 노드의 내용은 중괄호 사이에 배치되어야 합니다. \node[options] (name) at (0,0) {... };.

\foreach귀하의 예에서는 매크로에 저장된 루프 의 숫자를 노드에 배치할 수 있습니다 \x. 노드가 검은색으로 채워져 있으므로 내부의 텍스트는 표시되지 않습니다. 따라서 예를 들어 를 사용하여 채우기 색상을 변경하는 것이 좋습니다 fill=lightgray. 따라서 다음과 같이 작성할 수 있습니다 \node[fill=lightgray,circle,inner sep=2pt] (d\x) at (0,\x) {\x};.

세 개의 노드 세트 모두에 대해 이 작업을 수행하면 노드 내용의 길이가 다르므로 원의 크기도 달라집니다. 예를 들어 일부 노드에는 숫자 1개만 포함되는 반면 다른 노드에는 소수 구분 기호로 점 1개와 3개 숫자가 포함됩니다. minimum width=2.5em모든 노드에 대해 동일한 크기를 얻으려면 노드에 옵션(또는 이와 유사한 옵션)을 추가하고 싶을 수도 있습니다 .

마지막으로, 크기 증가로 인해 노드가 겹칠 수 있으므로 수평 거리를 그대로 유지하면서 수직 거리를 늘리는 y=1.25cm전체 옵션을 설정할 수 있습니다.tikzpicture

모든 것을 종합하면 다음과 같은 결과를 얻을 수 있습니다.

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{shapes.geometric,fit}

\begin{document}
\begin{tikzpicture}[y=1.25cm]
%put some nodes on the left
\foreach \x in {1,2,3}{
    \node[fill=lightgray,circle,inner sep=2pt,minimum width=2.5em] (d\x) at (0,\x) {\x};
}
\node[fit=(d1) (d2) (d3),ellipse,draw,minimum width=1cm] {}; 

%put some nodes on the center
\foreach \x[count=\xi] in {0.5,1.5,...,3.5}{
    \node[fill=lightgray,circle,inner sep=2pt,minimum width=2.5em] (r\xi) at (2,\x) {\x};
}
\node[fit=(r1) (r2) (r3) (r4),ellipse,draw,minimum width=1.5cm] {}; 

%put some nodes on the right
\foreach \x[count=\xi] in {0.75,1.5,...,3}{
    \node[fill=lightgray,circle,inner sep=2pt,minimum width=2.5em] (c\xi) at (4,\x) {\x};
}
\node[fit=(c1) (c2) (c3) (c4),ellipse,draw,minimum width=1.5cm] {};

\draw[-latex] (d1) -- (r2);
\draw[-latex] (d2) -- (r2);
\draw[-latex] (d3) -- (r4);
\draw[-latex] (r1) -- (c2);
\draw[-latex] (r2) -- (c3);
\draw[-latex] (d3) -- (r4);
\end{tikzpicture}
\end{document}

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


숫자 뒤에 배경이 필요하지 않은 경우 노드에 대한 옵션을 모두 삭제할 수 있습니다(또한 설정할 필요가 없습니다 y=1.25cm). 댓글에 제공한 그림과 유사한 색상을 추가하고 싶을 수도 있으므로 왼쪽 타원과 화살표 중 하나에 색상을 추가했습니다.

\documentclass[border=10pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{shapes.geometric,fit}

\begin{document}
\begin{tikzpicture}
%put some nodes on the left
\foreach \x in {1,2,3}{
    \node (d\x) at (0,\x) {\x};
}
\node[fit=(d1) (d2) (d3),ellipse,draw=blue,minimum width=1cm] {}; 

%put some nodes on the center
\foreach \x[count=\xi] in {0.5,1.5,...,3.5}{
    \node (r\xi) at (2,\x) {\x};
}
\node[fit=(r1) (r2) (r3) (r4),ellipse,draw,minimum width=1.5cm] {}; 

%put some nodes on the right
\foreach \x[count=\xi] in {0.75,1.5,...,3}{
    \node (c\xi) at (4,\x) {\x};
}
\node[fit=(c1) (c2) (c3) (c4),ellipse,draw,minimum width=1.5cm] {};

\draw[-latex,orange] (d1) -- (r2);
\draw[-latex] (d2) -- (r2);
\draw[-latex] (d3) -- (r4);
\draw[-latex] (r1) -- (c2);
\draw[-latex] (r2) -- (c3);
\draw[-latex] (d3) -- (r4);
\end{tikzpicture}
\end{document}

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

관련 정보