我有一张包含几个节点和几个标签的图表。我希望增加每个标签与其各自节点之间的距离(以防止其与图表的线条重叠)。正确的语法是什么?
\documentclass[tikz, border=10pt]{standalone}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\draw[step=1cm] (0,0) grid (5,1);
\node[label=above:\rotatebox{-45}{king} ] at (0.5,0.5) {0};
\node[label=above:\rotatebox{-45}{queen}] at (1.5,0.5) {1};
\node[label=above:\rotatebox{-45}{man} ] at (2.5,0.5) {0};
\node[label=above:\rotatebox{-45}{woman}] at (3.5,0.5) {0};
\node[label=above:\rotatebox{-45}{child}] at (4.5,0.5) {0};
\end{tikzpicture}
\end{document}
答案1
我认为是设置label distance
。
\documentclass[tikz, border=10pt]{standalone}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}[label distance=5mm]
\draw[step=1cm] (0,0) grid (5,1);
\node[label=above:\rotatebox{-45}{king} ] at (0.5,0.5) {0};
\node[label={[label distance=1cm]above:\rotatebox{-45}{queen}}] at (1.5,0.5) {1};
\node[label=above:\rotatebox{-45}{man} ] at (2.5,0.5) {0};
\node[label=above:\rotatebox{-45}{woman}] at (3.5,0.5) {0};
\node[label=above:\rotatebox{-45}{child}] at (4.5,0.5) {0};
\end{tikzpicture}
\end{document}
答案2
您可以放置带有数字的标签(例如 90 而不是上面的数字)并添加距离。添加方式label distance=<...>
如下:
\node[label={[label distance=2mm]90:\rotatebox{-45}{king}}]
参见:Tikz 手册http://vesta.informatik.rwth-aachen.de/ftp/pub/mirror/ctan/graphics/pgf/base/doc/pgfmanual.pdf
-> 3.9 在节点旁边添加标签(p.52)它说:数字而不是像左下方这样的内容 -> 17.10.2 标签选项标签(p.340):在主节点和标签节点之间另外插入。
梅威瑟:
\documentclass[tikz, border=10pt]{standalone}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\draw[step=1cm] (0,0) grid (5,1);
\node[label={[label distance=2mm]90:\rotatebox{-45}{king}}] at (0.5,0.5) {0};
\node[label={[label distance=2mm]90:\rotatebox{-45}{queen}}] at (1.5,0.5) {1};
\node[label={[label distance=2mm]90:\rotatebox{-45}{man}}] at (2.5,0.5) {0};
\node[label={[label distance=2mm]90:\rotatebox{-45}{woman}}] at (3.5,0.5) {0};
\node[label={[label distance=2mm]90:\rotatebox{-45}{child}}] at (4.5,0.5) {0};
\end{tikzpicture}
\end{document}