和谐地放置长度不同的节点

和谐地放置长度不同的节点

代码

\documentclass{article}
\usepackage{tikz}
\begin{document}
  \begin{tikzpicture}[font=\footnotesize, very thick]
  \def\r{3}
  \foreach \a/\n in {-2/{p-2}, -1/{p-1}, 0/0, 1/1, 2/2, 3/3, 4/4}
     \node[anchor=base] (\a) at (90+36*\a:\r) {$\circ$};
  \node (-3) at (90+36*-3:\r) {};
  \node (5) at (90+36*5:\r) {};
  \foreach \a/\name [remember=\a as \lasta (initially -3)] 
                in {-2/{p-3}, -1/{p-2}, 0/{p-1}, 1/0, 2/1, 3/2, 4/3, 5/4}
    {
    \draw[->, shorten >=5pt, shorten <=5pt] 
        (\lasta) 
        arc[radius=\r, start angle=90+36*(\lasta), end angle=90+36*(\a)]
        (\a);
    \node at (90+36*\lasta+18:\r+0.5) {$\alpha_{\name}$};
    }
  \foreach \a in { 1, ..., 14 } 
    {
    \node at (90+36*5+5*\a:\r) {$\cdot$};
    }
  \end{tikzpicture}
\end{document}

产生以下图片 在此处输入图片描述

我发现箭头上的标签位置相当令人困扰。我尝试了不少方法,但它们总是处于相当不对称的位置。

有什么办法可以让他们表现良好吗?

当然,正确的说法是出色地这里可以进行各种解释,但是我希望至少 alpha 能够显示在与箭头更一致的距离处。

附言:我手工放置标签,而不是将其作为弧线上的节点,因为这样看起来更好,但我认为这是个糟糕的选择...

答案1

我会为这一点设定锚点。

\documentclass[border=25pt]{standalone}
\usepackage{tikz}
\newcommand\aesub[1]{\makebox[0pt][l]{\raisebox{0pt}[\height][0pt]{\scriptsize$#1$}}}
\begin{document}
  \begin{tikzpicture}[font=\footnotesize, very thick]
  \def\r{3}
  \foreach \a/\n in {-2/{p-2}, -1/{p-1}, 0/0, 1/1, 2/2, 3/3, 4/4}
     \node[anchor=base] (\a) at (90+36*\a:\r) {$\circ$};
  \node (-3) at (90+36*-3:\r) {};
  \node (5) at (90+36*5:\r) {};
  \foreach \a/\name [remember=\a as \lasta (initially -3)] 
                in {-2/{p-3}, -1/{p-2}, 0/{p-1}, 1/0, 2/1, 3/2, 4/3, 5/4}
    {
    \draw[->, shorten >=5pt, shorten <=5pt] 
        (\lasta) 
        arc[radius=\r, start angle=90+36*(\lasta), end angle=90+36*(\a)]
        (\a);
    %% to avoid writing the same thing multiple times
    \pgfmathsetmacro\aeangle{90+36*\lasta+18}
    %% to see the node
    \node[circle,inner sep=0.5pt,fill] at (\aeangle:\r+0.5) {};
    \node[anchor=(\aeangle+180),outer sep=0pt,inner sep=0pt] at (\aeangle:\r+0.5) {$\alpha_{\aesub{\name}}$};
    %% old style for comparison purposes
    %% \node[anchor=(\aeangle+180),outer sep=0pt,inner sep=0pt] at (\aeangle:\r+0.5) {$\alpha_{\name}$};
    }
  \foreach \a in { 1, ..., 14 } 
    {
    \node at (90+36*5+5*\a:\r) {$\cdot$};
    }
  \end{tikzpicture}
\end{document}

在此处输入图片描述

我已将节点设为可见,以便您可以更好地看到位置。只需注释掉该行即可。此外,我添加了一个命令,将下标设置为零宽度、自然高度和零深度的框:自然高度留在那里,以便下标正确放置(即,不会太高)。这会产生一个不太理想的结果,即边界框没有完全设置好。但除此之外,此解决方案将锚点设置在 $\alpha$ 上,而不是整个 $\alpha_{...}$ 上。如果您发现设置了整个标签名称,则不要使用宏\aesub

答案2

这看上去是否更加美观呢?

偏移标签

\documentclass{article}
\usepackage{tikz}

\newlength{\tempwidth}

\begin{document}
  \begin{tikzpicture}[font=\footnotesize, very thick]
  \def\r{3}
  \foreach \a/\n in {-2/{p-2}, -1/{p-1}, 0/0, 1/1, 2/2, 3/3, 4/4}
     \node[anchor=base] (\a) at (90+36*\a:\r) {$\circ$};
  \node (-3) at (90+36*-3:\r) {};
  \node (5) at (90+36*5:\r) {};
  \foreach \a/\name [remember=\a as \lasta (initially -3)] 
                in {-2/{p-3}, -1/{p-2}, 0/{p-1}, 1/0, 2/1, 3/2, 4/3, 5/4}
    {
    \draw[->, shorten >=5pt, shorten <=5pt] 
        (\lasta) 
        arc[radius=\r, start angle=90+36*(\lasta), end angle=90+36*(\a)]
        (\a);
    \pgfextra{\settowidth{\tempwidth}{$\alpha_{\name}$}
       \pgfmathparse{0.5+0.005\tempwidth*cos(90+36*\lasta+18)}% fudge factor 0.005
       \global\let\temp=\pgfmathresult}
     \node at (90+36*\lasta+18:\r+\temp) {$\alpha_{\name}$};
    }
  \foreach \a in { 1, ..., 14 } 
    {
    \node at (90+36*5+5*\a:\r) {$\cdot$};
    }
  \end{tikzpicture}
\end{document}

这里的 alpha 是对称的(下标被忽略)。

rlap 下标

\documentclass{standalone}
\usepackage{tikz}

\newlength{\tempwidth}

\begin{document}
  \begin{tikzpicture}[font=\footnotesize, very thick]
  \def\r{3}
  \foreach \a/\n in {-2/{p-2}, -1/{p-1}, 0/0, 1/1, 2/2, 3/3, 4/4}
     \node[anchor=base] (\a) at (90+36*\a:\r) {$\circ$};
  \node (-3) at (90+36*-3:\r) {};
  \node (5) at (90+36*5:\r) {};
  \foreach \a/\name [remember=\a as \lasta (initially -3)] 
                in {-2/{p-3}, -1/{p-2}, 0/{p-1}, 1/0, 2/1, 3/2, 4/3, 5/4}
    {
    \draw[->, shorten >=5pt, shorten <=5pt] 
        (\lasta) 
        arc[radius=\r, start angle=90+36*(\lasta), end angle=90+36*(\a)]
        (\a);
     \node at (90+36*\lasta+18:\r+0.5) {$\alpha_{\rlap{$\scriptstyle\name$}}$};
    }
  \foreach \a in { 1, ..., 14 } 
    {
    \node at (90+36*5+5*\a:\r) {$\cdot$};
    }
  \node at (3.5,0) {\phantom{$alpha_{p-3}$}};% push right border
  \end{tikzpicture}
\end{document}

相关内容