如何在 Tikz 中将标签旋转节点下方 90 度?

如何在 Tikz 中将标签旋转节点下方 90 度?

我花了几个小时(:-))尝试使用“每个标签”方法用 90 度文本注释节点。虽然我可以旋转文本,但它的位置会转移到图片中某个更远的地方。我不想将“旋转”指令放到每个节点上,我宁愿用“每个标签”样式来定义它。

示例每个节点

\documentclass[12pt,a4paper,oneside]{report}
\usepackage[utf8]{inputenc}
\usepackage{pgf, tikz}
\usepackage{tikzscale}
\usetikzlibrary{shapes,arrows}
\usetikzlibrary{automata,calc,positioning}
\usetikzlibrary{angles,intersections,quotes,arrows.meta}

\begin{document}
\def \V {1.5}
\begin{tikzpicture}[every node/.style={line width=0.1mm, minimum size=1cm}]
\tikzstyle{every label}=[rotate=-90]
    \node[label={[label distance=0.1cm]:A},  circle, draw] (A)  at (1,0) { A};    
    \node[draw, circle] (B)  at (2,0) {B};   
    \node[draw, circle]  (C)  at (3,0) {C};  
    \node[draw, circle]  (D) at (4,0) {D}; 
    \node[draw, circle]  (E) at (5,0) {E}; 
    \node[draw, circle]  (F) at (6,0)  {F}; 
    \node[draw, circle]  (G) at (1,\V) {G};
    \node[draw, circle]  (H) at (2,\V) {H};
    \node[draw, circle]  (I) at (3,\V) {I};
    \node[draw, circle]  (J) at (4,\V) {J};
    \node[draw, circle]  (K) at (5,\V) {K};
    \node[draw, circle]  (L) at (6,\V) {L};

    \draw[->]  (B) to [bend left=60] (K) ;

\end{tikzpicture}    
\end{document}

答案1

您只需在旋转命令后定义标签的锚点:

\documentclass[12pt,a4paper,oneside]{report}
\usepackage{tikz}
\usetikzlibrary{angles,intersections,quotes,arrows.meta}

\begin{document}
\def \V {2}
\begin{tikzpicture}[
          C/.style = {circle, draw, minimum size=1cm},% every node influence on label node too,
every label/.style = {label distance=0pt, inner sep=1pt}
                    ]
    \node[C,label={[rotate=90, anchor=east]below:A}] (A)  at (1,0) { A};
    \node[C]  (B) at (2,0) {B};
    \node[C]  (C) at (3,0) {C};
    \node[C]  (D) at (4,0) {D};
    \node[C]  (E) at (5,0) {E};
    \node[C]  (F) at (6,0)  {F};
    \node[C]  (G) at (1,\V) {G};
    \node[C]  (H) at (2,\V) {H};
    \node[C]  (I) at (3,\V) {I};
    \node[C]  (J) at (4,\V) {J};
    \node[C]  (K) at (5,\V) {K};
    \node[C]  (L) at (6,\V) {L};

    \draw[->] (B.north) .. controls + (0,1) and + (0,-1) .. (K.south) ;

\end{tikzpicture}
\end{document}

在此处输入图片描述

答案2

经过进一步的研究,我找到了解决方案:为了将标签定位到我想要的位置,我必须添加“xshift”:

\node[label={[label distance=-0.5cm,red, xshift=-.5cm]below:label}, draw, circle] (A)  at (1,0) {A};

节点标签的定位

相关内容