当前代码如下:
\documentclass[tikz,border=3mm]{standalone}
\usepackage[T1]{fontenc}
\usepackage{polyglossia}
\setmainlanguage{spanish}
\usepackage{tikz}
\usetikzlibrary{arrows.meta, calc}
\tikzstyle{every picture}+=[remember picture]
\usepackage{musicography}
\usepackage{musixtex}
\input{musixlyr}
\input {musixcho}
\input {musixdat}%fecha
\input {musixfll}
\input {musixgre}%gregoriano
\input {musixper}%percusión
\input {musixppff}
\input {musixstr}
\input {musixvbm} % experimental vectorized beams
\input {musixdbr} % lineas de barras punteadas, discontinuas y arbitrariamente discontinuas
\input {musixbm} % compatibilidad garrapateas con ganchos o con barras
\input {musixbbm} % compatibilidad semi garrapateas con ganchos o con barras
%Rutinas para dibujar el piano
\newlength{\CtoBwd}%% Width of 7 adjacent white (natural) keys
\newlength{\Whitewd}%% Width of a natural key
\newlength{\Blackwd}%% Width of a black key
\newlength{\Whitefrontht}%% Distance from front of white key to black key
\newlength{\Backwdi}%% <<-- See below
\newlength{\Backwdii}%% <<-- See below
\newlength{\Backwdiii}%% <<-- See below
\newlength{\FronttoBack}%% Total length of a natural key
\newlength{\Blackht}%% Length of a black key
%% http://datagenetics.com/blog/may32016/index.html
\NewDocumentCommand{\drawaccidental}{mmmm}{% Lower left, sharp name, flat name, coordinate name for upper right of accidental
\draw[fill=black] (#1)
rectangle node[white,text width=\Backwdii,align=center]
{\bfseries\huge#2${}^\sharp$\\[1ex]#3${}^\flat$}
++ (\Blackwd,\Blackht)coordinate (#4);
}
\NewDocumentCommand{\drawname}{m}{% Coordinate name of lower left of key and name of key
\node at ($(#1) + (\Whitewd/2,\Whitefrontht/2)$) {\bfseries\Huge#1};
}
%% f b = \Backwdi
%% cs ds fs gs as = \Backwdii
%% d g a = \Backwdii
%% c e = \Backwdiii
\NewDocumentCommand{\drawkeyboard}{}{%
\draw (0,0)coordinate(C) -- ++(0,\FronttoBack) -- ++(\Backwdiii,0) --
++(0,-\Blackht)coordinate(CS) -| (\Whitewd,0)coordinate(D) -- cycle;
\drawaccidental{CS}{C}{D}{CS0}
\drawname{C}
\draw (D) -- ++(0,\Whitefrontht) -| (CS0) -- ++(\Backwdii,0) -- ++(0,-\Blackht)coordinate(DS)
-| (2\Whitewd,0)coordinate(E) -- cycle;
\drawaccidental{DS}{D}{E}{DS0}
\drawname{D}
\draw (E) -- ++(0,\Whitefrontht) -| (DS0) -- ++(\Backwdiii,0) -- ++(0,-\FronttoBack)coordinate(F)
-- cycle;
\drawname {E}
\draw (F) -- ++(0,\FronttoBack) -- ++(\Backwdi,0) -- ++(0,-\Blackht)coordinate(FS)
-| (4\Whitewd,0)coordinate(G) -- cycle;
\drawaccidental{FS}{F}{G}{FS0}
\drawname{F}
\draw (G) -- ++(0,\Whitefrontht) -| (FS0) -- ++(\Backwdii,0) -- ++(0,-\Blackht)coordinate(GS)
-| (5\Whitewd,0)coordinate(A) -- cycle;
\drawaccidental{GS}{G}{A}{GS0}
\drawname{G}
\draw (A) -- ++(0,\Whitefrontht) -| (GS0) -- ++(\Backwdii,0) -- ++(0,-\Blackht)coordinate(AS)
-| (6\Whitewd,0)coordinate(B) -- cycle;
\drawaccidental{AS}{A}{B}{AS0}
\drawname{A}
\draw (B) -- ++(0,\Whitefrontht) -| (AS0) -- ++(\Backwdi,0) -- ++(0,-\FronttoBack) -- cycle;
\drawname{B}
}
\begin{document}
%Dibujo del piano
\setlength{\CtoBwd}{6.5in} %% This varies between 160mm to 167mm depending upon manufacturer
\pgfmathsetlengthmacro{\tmpwd}{\CtoBwd/5880}\typeout{\tmpwd!!!!}
\setlength{\Whitewd}{\dimexpr \tmpwd*840\relax}
\setlength{\Blackwd}{\dimexpr \tmpwd*490\relax}
\setlength{\Blackht}{3.75in}
\setlength{\Whitefrontht}{2in}
\setlength{\FronttoBack}{\dimexpr \Whitefrontht + \Blackht\relax}
\setlength{\Backwdi}{\dimexpr\tmpwd*455\relax}
\setlength{\Backwdii}{\dimexpr\tmpwd*490\relax}
\setlength{\Backwdiii}{\dimexpr\tmpwd*525\relax}
\begin{tikzpicture}[scale=0.7,rounded corners=4pt]
%\foreach \oct in {0,...,3}{% for 4 octaves; vary at will
\foreach \oct in {0}{% for 4 octaves; vary at will
\begin{scope}[xshift=\oct*\CtoBwd]
\drawkeyboard
\end{scope}
}
%Poniendo etiquetas
\node[text width=1cm,align=center] (tonoCD) at (2.35,-1.0) {\textbf{1 tono}};
\node[text width=1cm,align=center] (tonoDE) at (4.7,-1.0) {\textbf{1 tono}};
\node[text width=1cm,align=center] (semiTonoEF) at (7.1,-1.0) {\textbf{$1/2$ tono}};
\node[text width=1cm,align=center] (tonoFG) at (9.4,-1.0) {\textbf{1 tono}};
\node[text width=1cm,align=center] (tonoGA) at (11.8,-1.0) {\textbf{1 tono}};
\node[text width=1cm,align=center] (tonoAB) at (14.2,-1.0) {\textbf{1 tono}};
\node[text width=1cm,align=center] (semiTonoBC) at (16.5,-1.0) {\textbf{$1/2$ tono}};
\end{tikzpicture}
\end{document}
我需要针对以下问题改进代码:
- 为标签添加边框和背景颜色:音调和半音。
- 将音符改为西班牙语:Do 代表 C、Re 代表 D、Mi 代表 E,等等。
- 减小钢琴的高度尺寸。
当前代码输出为:
感谢致敬
答案1
\documentclass[tikz,border=3mm]{standalone}
\usepackage[T1]{fontenc}
\usepackage{polyglossia}
\setmainlanguage{spanish}
\usepackage{tikz}
\usetikzlibrary{arrows.meta, calc,positioning}
\tikzstyle{every picture}+=[remember picture]
\usepackage{musicography}
\usepackage{musixtex}
\input{musixlyr}
\input {musixcho}
\input {musixdat}%fecha
\input {musixfll}
\input {musixgre}%gregoriano
\input {musixper}%percusión
\input {musixppff}
\input {musixstr}
\input {musixvbm} % experimental vectorized beams
\input {musixdbr} % lineas de barras punteadas, discontinuas y arbitrariamente discontinuas
\input {musixbm} % compatibilidad garrapateas con ganchos o con barras
\input {musixbbm} % compatibilidad semi garrapateas con ganchos o con barras
% Rutinas para dibujar el piano
\newlength{\CtoBwd}%% Width of 7 adjacent white (natural) keys
\newlength{\Whitewd}%% Width of a natural key
\newlength{\Blackwd}%% Width of a black key
\newlength{\Whitefrontht}%% Distance from front of white key to black key
\newlength{\Backwdi}%% <<-- See below
\newlength{\Backwdii}%% <<-- See below
\newlength{\Backwdiii}%% <<-- See below
\newlength{\FronttoBack}%% Total length of a natural key
\newlength{\Blackht}%% Length of a black key
%% http://datagenetics.com/blog/may32016/index.html
\NewDocumentCommand{\drawaccidental}{mmmm}{% Lower left, sharp name, flat name, coordinate name for upper right of accidental
\draw[fill=black] (#1)
rectangle node[white,text width=\Backwdii,align=center]
{\bfseries\large#2$^\sharp$\\[1ex]#3$^\flat$}
++ (\Blackwd,\Blackht)coordinate (#4);
}
\NewDocumentCommand{\drawname}{m}{% Coordinate name of lower left of key and name of key
\node at ($(#1) + (\Whitewd/2,\Whitefrontht/2)$) {\bfseries\large#1};
}
%% f b = \Backwdi
%% cs ds fs gs as = \Backwdii
%% d g a = \Backwdii
%% c e = \Backwdiii
\NewDocumentCommand{\drawkeyboard}{}{%
\draw (0,0)coordinate(Do) -- ++(0,\FronttoBack) -- ++(\Backwdiii,0) --
++(0,-\Blackht)coordinate(DoS) -| (\Whitewd,0)coordinate(Re) -- cycle;
\drawaccidental{DoS}{Do}{Re}{DoS0}
\drawname{Do}
\draw (Re) -- ++(0,\Whitefrontht) -| (DoS0) -- ++(\Backwdii,0) -- ++(0,-\Blackht)coordinate(ReS)
-| (2\Whitewd,0)coordinate(Mi) -- cycle;
\drawaccidental{ReS}{Re}{Mi}{ReS0}
\drawname{Re}
\draw (Mi) -- ++(0,\Whitefrontht) -| (ReS0) -- ++(\Backwdiii,0) -- ++(0,-\FronttoBack)coordinate(Fa)
-- cycle;
\drawname {Mi}
\draw (Fa) -- ++(0,\FronttoBack) -- ++(\Backwdi,0) -- ++(0,-\Blackht)coordinate(FaS)
-| (4\Whitewd,0)coordinate(Sol) -- cycle;
\drawaccidental{FaS}{Fa}{Sol}{FaS0}
\drawname{Fa}
\draw (Sol) -- ++(0,\Whitefrontht) -| (FaS0) -- ++(\Backwdii,0) -- ++(0,-\Blackht)coordinate(SolS)
-| (5\Whitewd,0)coordinate(La) -- cycle;
\drawaccidental{SolS}{Sol}{La}{SolS0}
\drawname{Sol}
\draw (La) -- ++(0,\Whitefrontht) -| (SolS0) -- ++(\Backwdii,0) -- ++(0,-\Blackht)coordinate(LaS)
-| (6\Whitewd,0)coordinate(Si) -- cycle;
\drawaccidental{LaS}{La}{Si}{LaS0}
\drawname{La}
\draw (Si) -- ++(0,\Whitefrontht) -| (LaS0) -- ++(\Backwdi,0) -- ++(0,-\FronttoBack)coordinate(Do1) -- cycle;
\drawname{Si}
}
% Dibujo del piano
\setlength{\CtoBwd}{6.5in} %% This varies between 160mm to 167mm depending upon manufacturer
\pgfmathsetlengthmacro{\tmpwd}{\CtoBwd/5880}\typeout{\tmpwd!!!!}
\setlength{\Whitewd}{\dimexpr \tmpwd*840\relax}
\setlength{\Blackwd}{\dimexpr \tmpwd*490\relax}
\setlength{\Blackht}{1.5in}
\setlength{\Whitefrontht}{1in}
\setlength{\FronttoBack}{\dimexpr \Whitefrontht + \Blackht\relax}
\setlength{\Backwdi}{\dimexpr\tmpwd*455\relax}
\setlength{\Backwdii}{\dimexpr\tmpwd*490\relax}
\setlength{\Backwdiii}{\dimexpr\tmpwd*525\relax}
\begin{document}
\begin{tikzpicture}[scale=0.7,rounded corners=4pt]
% \foreach \oct in {0,...,3}{% for 4 octaves; vary at will
\foreach \oct in {0}{% for 4 octaves; vary at will
\begin{scope}[xshift=\oct*\CtoBwd]
\drawkeyboard
\end{scope}
}
% Poniendo etiquetas
\tikzset{
space/.style={text width=1cm,align=center,draw,below=2mm of #1},
tono/.style={space=#1,fill=red!20},
semitono/.style={space=#1,fill=yellow!70},
}
\node[tono=Re] (tonoDoRe) {\textbf{1 tono}};
\node[tono=Mi] (tonoReMi) {\textbf{1 tono}};
\node[semitono=Fa] (semiTonoMiFa) {\textbf{$1/2$ tono}};
\node[tono=Sol] (tonoFaSol) {\textbf{1 tono}};
\node[tono=La] (tonoSolLa) {\textbf{1 tono}};
\node[tono=Si] (tonoLaSi) {\textbf{1 tono}};
\node[semitono=Do1] (semiTonoSiDo) {\textbf{$1/2$ tono}};
\end{tikzpicture}
\end{document}
答案2
这些musixtex
部分与该解决方案无关,主要基于此sgmoye 的回答。
\documentclass[tikz,border=3mm]{standalone}
\usepackage{polyglossia}
\setmainlanguage{spanish}
\usepackage{tgchorus}% added <<<<<<<<<<
\usepackage[T1]{fontenc}
\usepackage{tikz}
\usetikzlibrary{arrows.meta, calc}
\tikzstyle{every picture}+=[remember picture]
%% https://tex.stackexchange.com/a/527410/161015
%Rutinas para dibujar el piano
\newlength{\CtoBwd}%% Width of 7 adjacent white (natural) keys
\newlength{\Whitewd}%% Width of a natural key
\newlength{\Blackwd}%% Width of a black key
\newlength{\Whitefrontht}%% Distance from front of white key to black key
\newlength{\Backwdi}%% <<-- See below
\newlength{\Backwdii}%% <<-- See below
\newlength{\Backwdiii}%% <<-- See below
\newlength{\FronttoBack}%% Total length of a natural key
\newlength{\Blackht}%% Length of a black key
\NewDocumentCommand{\drawaccidental}{mmmm}{% Lower left, sharp name, flat name, coordinate name for upper right of accidental
\draw[fill=black] (#1) rectangle node{}++ (\Blackwd,\Blackht) coordinate (#4);
}
\NewDocumentCommand{\drawname}{m}{% Coordinate name of lower left of key and name of key
\node[font=\bfseries\large] at ($(#1) + (\Whitewd/2,\Whitefrontht/2)$) {#1};
}
\NewDocumentCommand{\drawkeyboard}{}{% names of notes in spanish <<<< <<<<<<<<<<
\draw (0,0)coordinate(DO) -- ++(0,\FronttoBack) -- ++(\Backwdiii,0) --
++(0,-\Blackht)coordinate(CS) -| (\Whitewd,0)coordinate(RE) -- cycle;
\drawaccidental{CS}{}{}{CS0}
\drawname{DO}
\draw (RE) -- ++(0,\Whitefrontht) -| (CS0) -- ++(\Backwdii,0) -- ++(0,-\Blackht)coordinate(DS)
-| (2\Whitewd,0)coordinate(MI) -- cycle;
\drawaccidental{DS}{}{}{DS0}
\drawname{RE}
\draw (MI) -- ++(0,\Whitefrontht) -| (DS0) -- ++(\Backwdiii,0) -- ++(0,-\FronttoBack)coordinate(FA)
-- cycle;
\drawname {MI}
\draw (FA) -- ++(0,\FronttoBack) -- ++(\Backwdi,0) -- ++(0,-\Blackht)coordinate(FS)
-| (4\Whitewd,0)coordinate(SOL) -- cycle;
\drawaccidental{FS}{F}{SOL}{FS0}
\drawname{FA}
\draw (SOL) -- ++(0,\Whitefrontht) -| (FS0) -- ++(\Backwdii,0) -- ++(0,-\Blackht)coordinate(GS)
-| (5\Whitewd,0)coordinate(LA) -- cycle;
\drawaccidental{GS}{SOL}{LA}{GS0}
\drawname{SOL}
\draw (LA) -- ++(0,\Whitefrontht) -| (GS0) -- ++(\Backwdii,0) -- ++(0,-\Blackht)coordinate(AS)
-| (6\Whitewd,0)coordinate(SI) -- cycle;
\drawaccidental{AS}{LA}{SI}{AS0}
\drawname{LA}
\draw (SI) -- ++(0,\Whitefrontht) -| (AS0) -- ++(\Backwdi,0) -- ++(0,-\FronttoBack) -- cycle;
\drawname{SI}
}
\begin{document}
%%%%Dibujo del piano
\setlength{\CtoBwd}{6.5in}
\pgfmathsetlengthmacro{\tmpwd}{\CtoBwd/5880}
\setlength{\Whitewd}{\dimexpr \tmpwd*840\relax}
\setlength{\Blackwd}{\dimexpr \tmpwd*490\relax}
\setlength{\Blackht}{1.75in}% changed <<<<<<<<<<<<<<<<<<<<<<
\setlength{\Whitefrontht}{1in}% changed <<<<<<<<<<<<<<<<<<<<<<
\setlength{\FronttoBack}{\dimexpr \Whitefrontht + \Blackht\relax}
\setlength{\Backwdi}{\dimexpr\tmpwd*455\relax}
\setlength{\Backwdii}{\dimexpr\tmpwd*490\relax}
\setlength{\Backwdiii}{\dimexpr\tmpwd*525\relax}
\begin{tikzpicture}[scale=0.7,rounded corners=4pt, tonos/.style={draw,text width=1.2cm, fill=#1, align =center, font=\bfseries}]% changed <<<
\foreach \oct in {0}{% for 4 octaves; vary at will
\begin{scope}[xshift=\oct*\CtoBwd]
\drawkeyboard
\end{scope}
}
%Poniendo etiquetas
\node[tonos={red!20}] (tonoCD) at (2.35,-1.0) {1 tono};
\node[tonos={red!20}] (tonoDE) at (4.7,-1.0) {1 tono};
\node[tonos={yellow!70}](semiTonoEF) at (7.1,-1.0) {1/2 tono};
\node[tonos={red!20}] (tonoFG) at (9.4,-1.0) {1 tono};
\node[tonos={red!20}] (tonoGA) at (11.8,-1.0) {1 tono};
\node[tonos={red!20}] (tonoAB) at (14.2,-1.0) {1 tono};
\node[tonos={yellow!70}](semiTonoBC) at (16.5,-1.0) {1/2 tono};
\end{tikzpicture}
\end{document}
答案3
根据Sigur代码解决方案,现在第1项已经解决如下:
\documentclass[tikz,border=3mm]{standalone}
\usepackage[T1]{fontenc}
\usepackage{polyglossia}
\setmainlanguage{spanish}
\usepackage{tikz}
\usetikzlibrary{arrows.meta, calc}
\tikzstyle{every picture}+=[remember picture]
\usepackage{musicography}
\usepackage{musixtex}
\input{musixlyr}
\input {musixcho}
\input {musixdat}%fecha
\input {musixfll}
\input {musixgre}%gregoriano
\input {musixper}%percusión
\input {musixppff}
\input {musixstr}
\input {musixvbm} % experimental vectorized beams
\input {musixdbr} % lineas de barras punteadas, discontinuas y arbitrariamente discontinuas
\input {musixbm} % compatibilidad garrapateas con ganchos o con barras
\input {musixbbm} % compatibilidad semi garrapateas con ganchos o con barras
%Rutinas para dibujar el piano
\newlength{\CtoBwd}%% Width of 7 adjacent white (natural) keys
\newlength{\Whitewd}%% Width of a natural key
\newlength{\Blackwd}%% Width of a black key
\newlength{\Whitefrontht}%% Distance from front of white key to black key
\newlength{\Backwdi}%% <<-- See below
\newlength{\Backwdii}%% <<-- See below
\newlength{\Backwdiii}%% <<-- See below
\newlength{\FronttoBack}%% Total length of a natural key
\newlength{\Blackht}%% Length of a black key
%% http://datagenetics.com/blog/may32016/index.html
\NewDocumentCommand{\drawaccidental}{mmmm}{% Lower left, sharp name, flat name, coordinate name for upper right of accidental
\draw[fill=black] (#1)
rectangle node[white,text width=\Backwdii,align=center]
{\bfseries\huge#2${}^\sharp$\\[1ex]#3${}^\flat$}
++ (\Blackwd,\Blackht)coordinate (#4);
}
\NewDocumentCommand{\drawname}{m}{% Coordinate name of lower left of key and name of key
\node at ($(#1) + (\Whitewd/2,\Whitefrontht/2)$) {\bfseries\Huge#1};
}
%% f b = \Backwdi
%% cs ds fs gs as = \Backwdii
%% d g a = \Backwdii
%% c e = \Backwdiii
\NewDocumentCommand{\drawkeyboard}{}{%
\draw (0,0)coordinate(C) -- ++(0,\FronttoBack) -- ++(\Backwdiii,0) --
++(0,-\Blackht)coordinate(CS) -| (\Whitewd,0)coordinate(D) -- cycle;
\drawaccidental{CS}{C}{D}{CS0}
\drawname{C}
\draw (D) -- ++(0,\Whitefrontht) -| (CS0) -- ++(\Backwdii,0) -- ++(0,-\Blackht)coordinate(DS)
-| (2\Whitewd,0)coordinate(E) -- cycle;
\drawaccidental{DS}{D}{E}{DS0}
\drawname{D}
\draw (E) -- ++(0,\Whitefrontht) -| (DS0) -- ++(\Backwdiii,0) -- ++(0,-\FronttoBack)coordinate(F)
-- cycle;
\drawname {E}
\draw (F) -- ++(0,\FronttoBack) -- ++(\Backwdi,0) -- ++(0,-\Blackht)coordinate(FS)
-| (4\Whitewd,0)coordinate(G) -- cycle;
\drawaccidental{FS}{F}{G}{FS0}
\drawname{F}
\draw (G) -- ++(0,\Whitefrontht) -| (FS0) -- ++(\Backwdii,0) -- ++(0,-\Blackht)coordinate(GS)
-| (5\Whitewd,0)coordinate(A) -- cycle;
\drawaccidental{GS}{G}{A}{GS0}
\drawname{G}
\draw (A) -- ++(0,\Whitefrontht) -| (GS0) -- ++(\Backwdii,0) -- ++(0,-\Blackht)coordinate(AS)
-| (6\Whitewd,0)coordinate(B) -- cycle;
\drawaccidental{AS}{A}{B}{AS0}
\drawname{A}
\draw (B) -- ++(0,\Whitefrontht) -| (AS0) -- ++(\Backwdi,0) -- ++(0,-\FronttoBack) -- cycle;
\drawname{B}
}
\begin{document}
%Dibujo del piano
\setlength{\CtoBwd}{6.5in} %% This varies between 160mm to 167mm depending upon manufacturer
\pgfmathsetlengthmacro{\tmpwd}{\CtoBwd/5880}\typeout{\tmpwd!!!!}
\setlength{\Whitewd}{\dimexpr \tmpwd*840\relax}
\setlength{\Blackwd}{\dimexpr \tmpwd*490\relax}
\setlength{\Blackht}{3.75in}
\setlength{\Whitefrontht}{2in}
\setlength{\FronttoBack}{\dimexpr \Whitefrontht + \Blackht\relax}
\setlength{\Backwdi}{\dimexpr\tmpwd*455\relax}
\setlength{\Backwdii}{\dimexpr\tmpwd*490\relax}
\setlength{\Backwdiii}{\dimexpr\tmpwd*525\relax}
\begin{tikzpicture}[scale=0.7,rounded corners=4pt]
%\foreach \oct in {0,...,3}{% for 4 octaves; vary at will
\foreach \oct in {0}{% for 4 octaves; vary at will
\begin{scope}[xshift=\oct*\CtoBwd]
\drawkeyboard
\end{scope}
}
%Poniendo etiquetas
\node[text width=1cm,align=center,draw,fill=red!20] (tonoCD) at (2.35,-1.0) {\textbf{1 tono}};
\node[text width=1cm,align=center,draw,fill=red!20] (tonoDE) at (4.7,-1.0) {\textbf{1 tono}};
\node[text width=1cm,align=center,draw,fill=yellow!70] (semiTonoEF) at (7.1,-1.0) {\textbf{$1/2$ tono}};
\node[text width=1cm,align=center,draw,fill=red!20] (tonoFG) at (9.4,-1.0) {\textbf{1 tono}};
\node[text width=1cm,align=center,draw,fill=red!20] (tonoGA) at (11.8,-1.0) {\textbf{1 tono}};
\node[text width=1cm,align=center,draw,fill=red!20] (tonoAB) at (14.2,-1.0) {\textbf{1 tono}};
\node[text width=1cm,align=center,draw,fill=yellow!70] (semiTonoBC) at (16.5,-1.0) {\textbf{$1/2$ tono}};
\end{tikzpicture}
\end{document}