tikz로 십자가 그리기

tikz로 십자가 그리기

만약 내가한다면

\draw (1,1) circle (1pt)

1pttikz는 직경이 에 있는 작은 원을 그립니다 (1,1).

cross다음과 같은 경로를 어떻게 정의할 수 있습니까?

\draw (1,1) cross (1pt)

직경이 있는 작은 십자가를 그립니다 1pt(원처럼 크기 조절 가능)?

답변1

cross에 해당하는 명령은 circle존재하지 않지만 라이브러리 의 노드를 TiKZ사용할 수 있습니다 . 이런 종류의 노드는 노드의 텍스트 위에 교차를 추가하지만 원하는 대로 적용하기가 쉽습니다.cross outshapes.misc

\tikzset{cross/.style={cross out, draw, 
         minimum size=2*(#1-\pgflinewidth), 
         inner sep=0pt, outer sep=0pt}}

반경=1pt인 원을 그리 므로 circle (1pt)전체 크기는 2pt가 되며 cross노드의 크기는 minimum size=2*(#1-\pgflinewidth)및 로 정의 inner되고 outer간격은 로 고정됩니다 0pt.

교차 각도가 원하는 각도가 아닐 경우 rotate옵션으로 변경할 수 있습니다. 다음으로 몇 가지 예가 있습니다. 또한 circles원과 십자가의 크기가 동일하다는 것을 보여주기 위해 그 위에 배치했습니다 .

\documentclass[tikz, border=2mm]{standalone}
\usetikzlibrary{shapes.misc}

\tikzset{cross/.style={cross out, draw=black, minimum size=2*(#1-\pgflinewidth), inner sep=0pt, outer sep=0pt},
%default radius will be 1pt. 
cross/.default={1pt}}

\begin{document}
\begin{tikzpicture}[]

\draw (0,0) circle (1pt);

\draw (.5,0) node[cross,rotate=10] {};
\draw (.5,0) circle (1pt);

\draw (0,.5) circle (1pt);
\draw (0,.5) node[cross,red] {};

\draw (.5,.5) node[cross,rotate=30] {};

\draw (0.25,.25) circle (2pt);
\draw (0.25,.25) node[cross=2pt,rotate=45,green]{};
\end{tikzpicture}
\end{document}

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

답변2

다음을 사용하는 대체 솔루션 pic:

\documentclass[]{standalone}

\usepackage{tikz}
\usepackage{pgfplots}
\pgfplotsset{compat=1.16}

\tikzset{
    cross/.pic = {
    \draw[rotate = 45] (-#1,0) -- (#1,0);
    \draw[rotate = 45] (0,-#1) -- (0, #1);
    }
}

\begin{document}



\begin{tikzpicture}

    \draw (0,0) circle (1pt);

    \path (.5,0) pic[rotate = 10] {cross=1pt};
    \draw (.5,0) circle (1pt);

    \draw (0,.5) circle (1pt);
    \path (0,.5) pic[red] {cross=1pt};

    \draw (.5,.5) pic[rotate = 30] {cross=1pt};

    \draw (0.25,.25) circle (2pt);
    \draw (0.25,.25) pic[rotate=45,green] {cross=2pt};
\end{tikzpicture}

\end{document}

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

답변3

해당 위치에 "x"를 쓸 수 있습니다.

\draw (1,1) node {x};

그런 다음 다음과 같이 글꼴 크기를 사용하여 크기를 조정할 수 있습니다.

\draw (1,1) node {\Huge x};

'x'의 중심은 실제로 주어진 좌표에 정확하게 배치됩니다.

관련 정보