
以下のコード セクションには、ラベル「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
ラベルが存在するはずだ外コンテンツとラベルの混同を避けるためにノードを作成します。最も簡単なのは、ラベル付け用のノードを追加することです。
\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}