使用 TikZ 和管风琴排列间距

使用 TikZ 和管风琴排列间距

我正在尝试绘制 61 个风琴管的总体图表——风琴键盘上有 61 个键(踏板上有 32 个)。出于声学原因,管子的布局通常是偶数管在右边(比如说),奇数管在左边。我差不多做到了,只是管子 1 和 2 之间的间距是奇数。以下是简单(太简单了?)的代码:

\documentclass{article}

\usepackage{tikz}

\begin{document}

\begin{tikzpicture}
    \foreach \x in {1,2,...,61} {%
        %% Use **either** of the following two lines:
        \pgfmathsetmacro{\pipel}{.25*2^((61-\x)/12)}% Longest pipe in the middle
        %\pgfmathsetmacro{\pipel}{.25*2^((\x)/12)}% Longest pipe at the left
        \pgfmathsetmacro{\posf}{ifthenelse(isodd(\x),-1,1)}% Odd to the left, even to the right
        \draw[thick] (\posf*\x/10,0) -- (\posf*\x/10,\pipel)node[above]{\tiny\x};
    }
\end{tikzpicture}

\end{document}

输出结果如下:

Rank of organ pipes

我错过了什么?

答案1

我添加了\posf对位置的依赖转变,如下所示(\posf*\x/10-.05*\posf,0)

\documentclass{article}

\usepackage{tikz}

\begin{document}

\begin{tikzpicture}
    \foreach \x in {1,2,...,61} {%
        %% Use **either** of the following two lines:
        \pgfmathsetmacro{\pipel}{.25*2^((61-\x)/12)}% Longest pipe in the middle
        %\pgfmathsetmacro{\pipel}{.25*2^((\x)/12)}% Longest pipe at the left
        \pgfmathsetmacro{\posf}{ifthenelse(isodd(\x),-1,1)}% Odd to the left, even to the right
        \draw[thick] (\posf*\x/10-.05*\posf,0) -- 
          (\posf*\x/10-.05*\posf,\pipel)node[above]{\tiny\x};
    }
\end{tikzpicture}

\end{document}

enter image description here

相关内容