将工作 tikzpicture 转换为带参数的 \newcommand

将工作 tikzpicture 转换为带参数的 \newcommand

我正在尝试改变解决方案问题

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{tikzmark}
\usepackage{leadsheets}
\setchords{
  major-seven = \textsuperscript{$\Delta$} ,
  major-nine = \textsuperscript{$\Delta$9}
}

\begin{document}

\tikzmark{ii7}\writechord{Cmi7}\qquad
\tikzmark{V7}\writechord{F7}\qquad
\tikzmark{I}\writechord{Bbmaj7}
\begin{tikzpicture}[remember picture, overlay]
  \draw[->]
    ([shift={(.3em,1em)}]pic cs:V7) to[bend left]
    ([shift={(.3em,1em)}]pic cs:I) ;
  \draw
    ([shift={(.3em,-.3em)}]pic cs:ii7)
    --++ (0,-1ex) -|
    ([shift={(.3em,-.3em)}]pic cs:V7) ;
\end{tikzpicture}

\end{document}

变成一个带有三个参数的函数。这是我稍微简化的尝试:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{tikzmark}

\newcommand{\Test}[3]{%
\begin{tikzpicture}[remember picture, overlay]
  \draw[->]
    ([shift={(.3em,1em)}]pic cs: #3) to[bend left]
    ([shift={(.3em,1em)}]pic cs: #1);
  \draw
    ([shift={(.3em,-.3em)}]pic cs: #2)
    --++ (0,-1ex) -|
    ([shift={(.3em,-.3em)}]pic cs: #3) ;
\end{tikzpicture}%
}

\begin{document}
 \Test{I}{ii7}{V7}
 \end{document}

然而,输出明显存在一些问题,如下图所示:

在此处输入图片描述

你能发现错误吗?

编辑:我希望能够毫无问题地以紧凑的方式堆叠一堆,类似于下面的示例:

\Test{C}{Dm7}{G7}
\Test{D}{Em7}{A7}
\Test{E}{Fm7}{B$/flat$7}

答案1

根据 OP 评论进行编辑。

重新编辑,以便\tikzmark即使重复使用相同的和弦名称也会创建唯一的和弦名称。

重新编辑以提供 OP 喜欢的和弦顺序。

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{tikzmark}
\usepackage{leadsheets}

\newcounter{cdct}
\newcommand\Test[3]{\stepcounter{cdct}%
  \Testaux{\thecdct}{#1}{#2}{#3}}

\newcommand\Testaux[4]{%
\tikzmark{#1A}\writechord{#2}\qquad
\tikzmark{#1B}\writechord{#3}\qquad
\tikzmark{#1C}\writechord{#4}
\begin{tikzpicture}[remember picture, overlay]
  \draw[->]
    ([shift={(.3em,1em)}]pic cs:#1B) to[bend left]
    ([shift={(.3em,1em)}]pic cs:#1C) ;
  \draw
    ([shift={(.3em,-.3em)}]pic cs:#1A)
    --++ (0,-1ex) -|
    ([shift={(.3em,-.3em)}]pic cs:#1B) ;
\end{tikzpicture}%
}
\begin{document}
\Test{Dm7}{G7}{C}
\Test{Em7}{A7}{D}
\Test{Fm7}{Bb7}{Eb}

\bigskip\Test{Dm7}{G7}{C}\par
\bigskip\Test{Em7}{A7}{D}\par
\bigskip\Test{Fm7}{Bb7}{Eb}
\end{document}

在此处输入图片描述

答案2

我对 Steven B. Segletes 提供的答案添加了自己的变体。

1-ii-subV7-I 节奏现已包含(虚线)。

2-两个支架和箭头均已调整并居中。

3-允许混合使用虚线​​/非虚线节奏

4小调和弦表达-min

5 小调七个半减和弦由-7b5

您可以通过自定义选项来删除选项 4 和 5 \setchords{}

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{tikzmark}
\usepackage{leadsheets}

\setchords{
 major-seven =$\Delta$7,%$\Delta$\arabicnumeral{7},
 major-nine = $\Delta$9,
 minor = -,
 half-dim = {($\flat 5$)}
}

\newcounter{cdct}
\newcommand\Dominant[3]{\stepcounter{cdct}%
  \Dominantaux{\thecdct}{#1}{#2}{#3}}
\newcommand\Dominantaux[4]{%
\tikzmark{#1#2}\writechord{#2}\qquad
\tikzmark{#1#3}\writechord{#3}\qquad
\tikzmark{#1#4}\writechord{#4}
\begin{tikzpicture}[remember picture, overlay]
  \draw[->]
    ([shift={(.6em,1em)}]pic cs:#1#3) to[bend left]
    ([shift={(.2em,1em)}]pic cs:#1#4) ;
  \draw
    ([shift={(.8em,-.3em)}]pic cs:#1#2)
    --++ (0,-1ex) -|
    ([shift={(.6em,-.3em)}]pic cs:#1#3) ;
\end{tikzpicture}%
}


\newcommand\Subdominant[3]{\stepcounter{cdct}%
  \Subdominantaux{\thecdct}{#1}{#2}{#3}}
\newcommand\Subdominantaux[4]{%
\tikzmark{#1#2}\writechord{#2}\qquad
\tikzmark{#1#3}\writechord{#3}\qquad
\tikzmark{#1#4}\writechord{#4}
\begin{tikzpicture}[remember picture, overlay]
  \draw[dashed,->]
    ([shift={(.6em,1em)}]pic cs:#1#3) to[bend left]
    ([shift={(.2em,1em)}]pic cs:#1#4) ;
  \draw[dashed]
    ([shift={(.8em,-.3em)}]pic cs:#1#2)
    --++ (0,-1ex) -|
    ([shift={(.6em,-.3em)}]pic cs:#1#3) ;
\end{tikzpicture}%
}
%
    
%%% Mixed %%%
\newcommand\Dominantmix[3]{\stepcounter{cdct}%
  \Dominantmixaux{\thecdct}{#1}{#2}{#3}}
\newcommand\Dominantmixaux[4]{%
\tikzmark{#1#2}\writechord{#2}\qquad
\tikzmark{#1#3}\writechord{#3}\qquad
\tikzmark{#1#4}\writechord{#4}
\begin{tikzpicture}[remember picture, overlay]
  \draw[->]
    ([shift={(.6em,1em)}]pic cs:#1#3) to[bend left]
    ([shift={(.2em,1em)}]pic cs:#1#4) ;
  \draw[dashed]
    ([shift={(.8em,-.3em)}]pic cs:#1#2)
    --++ (0,-1ex) -|
    ([shift={(.6em,-.3em)}]pic cs:#1#3) ;
\end{tikzpicture}%
}

\newcommand\Subdominantmix[3]{\stepcounter{cdct}%
  \Subdominantmixaux{\thecdct}{#1}{#2}{#3}}
\newcommand\Subdominantmixaux[4]{%
\tikzmark{#1#2}\writechord{#2}\qquad
\tikzmark{#1#3}\writechord{#3}\qquad
\tikzmark{#1#4}\writechord{#4}
\begin{tikzpicture}[remember picture, overlay]
  \draw[dashed,->]
    ([shift={(.6em,1em)}]pic cs:#1#3) to[bend left]
    ([shift={(.2em,1em)}]pic cs:#1#4) ;
  \draw
    ([shift={(.8em,-.3em)}]pic cs:#1#2)
    --++ (0,-1ex) -|
    ([shift={(.6em,-.3em)}]pic cs:#1#3) ;
\end{tikzpicture}%
}

%


\begin{document}

\bigskip\Dominant{D-7}{G7}{Cmaj7}\par

\bigskip\Subdominant{Abmi7}{G7}{Gb7}\par

\bigskip\Subdominant{A-7}{Ab7}{G-7}\par

\bigskip\Dominant{Ami7/o}{D7}{Gmi7}\par

\bigskip\Dominant{Gmi7/o}{C7}{Fmaj7}\par

\bigskip\Subdominantmix{Ami7}{D7}{Dbmi7}\par

\bigskip\Dominantmix{Db-7}{C7}{Fmaj7}\par

\end{document}

在此处输入图片描述

理想情况下,我希望降低预设的数字\textsuperscript{}。如果有人知道如何操作,请发表评论,谢谢。

相关内容