암호

암호

아래 코드 섹션이 있는데 "B"라는 레이블이 모서리 바깥쪽에 표시됩니다. 어떻게 안쪽 모서리로 바꿀 수 있나요? 아니면 라벨을 붙일 만한 다른 좋은 제안이 있나요?

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{positioning,fit,calc}
\begin{document}

\begin{tikzpicture}[inner sep=0mm,outer sep=0,node distance=4em,
  box/.style={draw,anchor=west,minimum width=10em,minimum height=3em},
]
  \node (A) [box] {A};
  \node (B) [below=of A.west,box,label=south west:B] {};  
\end{tikzpicture}
\end{document}

출력 그림은 다음과 같습니다

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

답변1

라벨이 존재해야 합니다.밖의내용과 라벨 사이의 혼동을 피하기 위한 노드입니다. 가장 쉬운 IMO는 라벨링을 위해 추가 노드를 추가하는 것입니다.

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{positioning,fit,calc}
\begin{document}

\begin{tikzpicture}[inner sep=0mm,outer sep=0,node distance=4em,
  box/.style={draw,anchor=west,minimum width=10em,minimum height=3em},
]
  \node (A) [box] {A};
  \node (B) [below=of A.west,box] {}node at ($(B.south west) +(0.15,0.15)$) {B};
\end{tikzpicture}
\end{document}

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

답변2

@Harish의 솔루션(내 생각에 더 쉽다고 생각함)의 대안은 레이블 노드의 앵커를 수동으로 설정하는 것입니다. 나는 팔로우한다이 답변 그리고 inside라벨이 노드 "내부"에 배치되도록 하는 키를 정의합니다.

\usepackage{etoolbox}
\makeatletter
\tikzset{inside/.code=\preto\tikz@auto@anchor{\pgf@x-\pgf@x\pgf@y-\pgf@y}}
\makeatother

그런 다음 이 키를 다른 옵션(예: 레이블 노드에 추가 패딩 제공) label과 함께 작업 에 전달할 수 있습니다.inner sep=1pt

암호

\documentclass[border=2pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{positioning,fit,calc}
\usepackage{etoolbox}
\makeatletter
\tikzset{inside/.code=\preto\tikz@auto@anchor{\pgf@x-\pgf@x\pgf@y-\pgf@y}}
\makeatother

\begin{document}

\begin{tikzpicture}[inner sep=0mm,outer sep=0,node distance=4em,
  box/.style={draw,anchor=west,minimum width=10em,minimum height=3em},
]
  \node (A) [box] {A};
  \node (B) [below=of A.west,box,label={[inside,inner sep=1pt]south west:B}] {};  
\end{tikzpicture}
\end{document}

산출

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

답변3

이 시도는 @Harish 및 @Kevin의 솔루션(쉽고 간단하다고 생각함)과 비교할 때 대체 솔루션이기도 합니다. 첫 번째 필요 calc, 다른 필요 inside/.code. 이 솔루션은 노드 위치 명령을 사용 anchor합니다 .at

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

암호

\documentclass[border=10pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{positioning,fit,calc}
\begin{document}

\begin{tikzpicture}[inner sep=0.1mm,outer sep=0,node distance=4em,
  box/.style={draw,anchor=west,minimum width=10em,minimum height=3em},
]
  \node (A) [box] {A};
  \node (B) [below=of A.west, box] {}; 
  \node     [anchor=south west, at=(B.south west)]{B};
\end{tikzpicture}
\end{document}

관련 정보