편집하다

편집하다
\documentclass[border=2mm, tikz]{standalone}    
\usetikzlibrary{shapes.geometric}    
\begin{document}
\begin{tikzpicture}[    
   x=7.5mm,y=4.34mm,    
   box/.style={    
      regular polygon,  
      regular polygon sides=6,         
      minimum size=10mm,           
      inner sep=0mm, outer sep=0mm,    
      draw}
 ]
\node [box] (innerbox) {};    
\foreach \x [evaluate=\x as \y using {int(ifthenelse(\x+2>6,\x-4,\x+2))}] in {1,...,6}     
 \node [box,anchor=corner \y] at (innerbox.corner \x) {};    
\end{tikzpicture}    
\end{document}

예를 들어 다음 그림과 같이 육각형의 이름을 지정하고 싶습니다. 여기에 이미지 설명을 입력하세요

답변1

코드를 있는 그대로 컴파일할 수 없습니다. 컴파일되지 않는 것이 문제가 아닌 한 예제를 게시하기 전에 코드가 컴파일되는지 확인하십시오. 이 경우 요청한 오류가 발생하는지 확인하십시오.

이 코드는 귀하에게 적합하지 않습니다. 모든 종류의 무작위로 이상한 위치에 단락 나누기가 포함되어 있어 오류가 발생하고 오류가 발생하기 때문에 오류 없이 표시되는 출력을 생성할 수 없습니다.

질문에 관해서는 왜 루프에서 두 번째 변수를 사용할 수 없습니까?

\documentclass[border=5pt, tikz]{standalone}
\usetikzlibrary{shapes.geometric}
\begin{document}
\begin{tikzpicture}[
  x=7.5mm,y=4.34mm,
  box/.style={
    regular polygon,
    regular polygon sides=6,
    minimum size=10mm,
    inner sep=0mm, outer sep=0mm,
    draw}
  ]
  \node [box] (innerbox) {g};
  \foreach \i/\j [evaluate=\i as \k using {int(ifthenelse(\i+2>6,\i-4,\i+2))}] in {1/a,2/b,3/c,4/d,5/e,6/f}
  \node [box,anchor=corner \k] at (innerbox.corner \i) {\j};
\end{tikzpicture}
\end{document}

벌집

편집하다

노드의 이름만 지정하면 되도록 단순화할 수도 있습니다. 예를 들어:

\documentclass[border=5pt, tikz]{standalone}
\usetikzlibrary{shapes.geometric}
\begin{document}
\begin{tikzpicture}[
  box/.style={
    regular polygon,
    regular polygon sides=6,
    minimum size=10mm,
    inner sep=0mm,
    outer sep=0mm,
    inner color=orange!75!red!50!yellow,
    outer color=orange!75!red!75!yellow,
    draw=orange,
    text=red,
  },
  ]
  \node [box] (innerbox) {7};
  \foreach \i [count=\k from 0, evaluate=\k as \j using {int(60*\k+30)}, evaluate=\j as \l using {(int(\j+180))} ] in {10,6,4,3,1,9}
  \node (h\k) [box,  anchor=\l] at (innerbox.\j) {\i};
\end{tikzpicture}
\end{document}

(벌을 위해) 다음을 생성합니다:

꿀벌을 위한 벌집

관련 정보