1

I am trying to draw accordion keyboard layout with Tikz To have results like this with modified variable, Could someone helps me to create something similar with Tikz ? Does anyone have any code exemple close to this ? : [![enter image description here][1]][1]

Could someone helps me to create something similar with Tikz ? Does anyone have any code exemple close to this ?

I am really new in Programmation and I thanks you by advance for your help !

[1]:

1 Answer 1

3

Here is my attempt at creating the seemingly evenly placed array of circles on the right image:

\documentclass[tikz,border=1mm]{standalone}

\usepackage{musicography}

\usetikzlibrary{matrix,shapes.multipart}


\begin{document}

\begin{tikzpicture}[%
    mycirc/.style={%
        draw,circle split,
        minimum width=1.5cm,minimum height=1.5cm
    },
    accord/.style={mycirc},
    basse/.style={mycirc,very thick}
]
    \matrix[%
        matrix of nodes,
        every node/.style={anchor=center},
        every odd row/.style={nodes={accord}},
        every even row/.style={nodes={basse}},
        row sep=5mm,column sep=5mm
    ]{%
        maj\nodepart{lower}min
        & maj\nodepart{lower}maj
        & maj\nodepart{lower}min
        \\
        SI\nodepart{lower}DO\sh
        & MI\fl\nodepart{lower}SI\fl
        & SOL\sh\nodepart{lower}SI
        \\

        maj\nodepart{lower}min
        & maj\nodepart{lower}min
        & maj\nodepart{lower}maj
        \\
        LA\nodepart{lower}FA\sh
        & MI\fl\nodepart{lower}LA
        & SOL\sh\nodepart{lower}RE
        \\

        maj\nodepart{lower}maj
        & |[circle,minimum width=1.5cm,minimum height=1.5cm]|
          maj
        & maj\nodepart{lower}maj
        \\
        RE\nodepart{lower}DO
        & |[circle,minimum width=1.5cm,minimum height=1.5cm]|
          FA
        & DO\sh\nodepart{lower}SOL
        \\
    };
\end{tikzpicture}

\end{document}

output

Explanation

Right after \begin{tikzpicture} I define some styles:

  • mycirc is just a split circle with some minimal specified dimensions (so that the circles are evenly sized)
  • accord and basse are just extensions: accord adds nothing extra and just acts as an alias but basse also makes the shape very thick

I then use a matrix to easily create all the accord and basse nodes. Note that you do not have to use the every odd/even row part, it just avoids explicitly specifying the style to use for each element of the matrix.

I hope this helps a little. You can do something similar with the keyboard on the left, but that requires some more advanced positioning (possibly with something other than a matrix).


UPDATE 2020-12-01: Here is another tikzpicture that draws the left image. It uses the chains library instead of a matrix and some loops to avoid writing out all the nodes. There is definitely room for improvements (for example to avoid writing out all the numbers in the loop), but this is what I got so far.

\documentclass[tikz,border=1mm]{standalone}

\usepackage{musicography}

\usetikzlibrary{chains,positioning,shapes.multipart}


\begin{document}

\begin{tikzpicture}[%
    node distance=2mm,
    accord/.style={%
        draw,circle split,anchor=center,
        minimum width=1.5cm,minimum height=1.5cm
    },
    lb/.style={%
        font={\scriptsize},gray,
        label distance=-2mm,xshift=-7.5mm
    },
    start chain=1 going below,
    start chain=2 going below,
    start chain=3 going below,
]
    \node[%
        accord,on chain=1,label={[lb]above:1}
    ] (L) {DO\sh\nodepart{lower}MI\fl};
    \foreach \t/\b/\n in {%
        RÉ/FA\sh/2,SOL/LA/3,SI/DO/4,RÉ/MI/5,SOL/FA\sh/6,
        SI/LA/7,RÉ/DO/8,SOL/MI/9,SI/FA\sh/10,RÉ/LA\sh/11,
        SOL/DO/12
    } \node[%
        accord,on chain=1,label={[lb]above:\n}
    ] {\t\nodepart{lower}\b};

    \node[%
        accord,on chain=2,below right=-2.5mm and 8mm of L,
        label={[lb]above:{1'}}
    ] (M) {LA\nodepart{lower}SOL\sh};
    \foreach \t/\b/\n in {%
        SOL/SI/2,DO/RÉ/3,MI/FA/4,SOL/LA/5,DO/SI/6,MI/RÉ/7,
        SOL/FA/8,DO/LA/9,MI/SI/10,SOL/RÉ/11
    } \node[%
        accord,on chain=2,label={[lb]above:{\n'}}
    ] {\t\nodepart{lower}\b};

    \node[%
        accord,on chain=3,below right=-2.5mm and 8mm of M,
        label={[lb]above:{1''}}
    ] {SOL\sh\nodepart{lower}SI\fl};
    \foreach \t/\b/\n in {%
        SI\fl/DO\sh/2,MI\fl/SOL/3,SOL\sh/SOL\sh/4,SI\fl/SI\fl/5,
        MI\fl/DO\sh/6,SOL\sh/SOL/7,SI\fl/SOL\sh/8,MI\fl/SI\fl/9,
        SOL\sh/DO\sh/10
    } \node[%
        accord,on chain=3,label={[lb]above:{\n''}}
    ] {\t\nodepart{lower}\b};
\end{tikzpicture}

\end{document}

output of code for image on the left


UPDATE 2021-03-28: The following is one way to arrange the whole thing.

Create all four figures in separate documents (I named these top.tex, left.tex, right.tex, and bottom.tex), all using the standalone document class. You can now remove the border option from the beginning of each of these, it was only for aesthetic purposes when the figures were rendered separately. The standalone package (there is a documentclass and a package as well) allows you to simply do eg. \input{top} to add the output of the standalone document named top.tex.

Now all you need to do is arrange the four figures on one page. This is a lot trickier to do in LaTeX than it sounds. Having tried several methods, I think using tikz yet again to arrange the entire document works best. Examine the code of the final document: it uses tikz to position the individual figures relative to the document’s text area (with some additional ugly manual adjustments).

But first, let’s see the other two figures. They are a lot easier to draw. The top one is simply a circle, a line that goes from the left of the circle to the right (plus a few centimetres) and some text labels:

\documentclass[tikz]{standalone}

\usetikzlibrary{calc,positioning}


\begin{document}

\begin{tikzpicture}
    \node[draw,circle,minimum width=1.5cm] (c) {};
    \draw (c.west) -- ($(c.east)+(3cm,0cm)$);
    \node[right=1mm of c,yshift=2mm] {\itshape Poussé};
    \node[right=1mm of c,yshift=-2mm] {\itshape Tiré};
\end{tikzpicture}

\end{document}

The bottom is even easier: just two circles and two labels.

\documentclass[tikz]{standalone}

\usetikzlibrary{positioning}


\begin{document}

\begin{tikzpicture}[accord/.style={draw,circle,minimum width=1.5cm}]
    \node[accord] (a) {};
    \node[accord,very thick,below=2mm of a] (b) {};
    \node[right=1mm of a] {\itshape Accord};
    \node[right=1mm of b] {\itshape Basse};
\end{tikzpicture}

\end{document}

Now to put it all together. There is one more thing: the title in the top left corner. I managed to get something similar using a tabular environment. This is how it looks:

\documentclass[a4paper]{article}

% to set margins
\usepackage[hmargin=1cm,top=1cm,bottom=2.5cm]{geometry}

% to input standalone documents within this one
\usepackage{standalone}
% packages and libraries used in included standalone documents
\usepackage{tikz,musicography}
\usetikzlibrary{calc,chains,matrix,positioning,shapes.multipart}

% to get tikz node for document body (-> current page text area)
\usepackage{tikzpagenodes}

% to get multirow cells in tables
\usepackage{multirow}

% to be able to vertically write text
\usepackage{rotating}


% title drawing command
\newcommand\drawtitle{%
    \noindent
    \bgroup% so that arraystretch only applies here
    \def\arraystretch{2}
    \begin{tabular}{l|p{6cm}}
        \multirow{4}{*}{%
            \begin{turn}{90}
                \Large\bfseries Plan de clavier
            \end{turn}
        }
        & {\Large\bfseries Système Le Tron / Laloy } \\[-2ex]
        %                                               ^^^^
        %       -2ex horizontal shift compensates for \Large
        & Tonalité: sol-do-altératíons. \\
        & Modèles à trois rangèes (33 boutons) \par et dix-huit
          basses \\
        & {} % empty row for vertical line to continue
    \end{tabular}
    \egroup
}


\begin{document}

\thispagestyle{empty} % get rid of page number

\drawtitle

\begin{tikzpicture}[remember picture,overlay]
    \node[anchor=north]
        at ($(current page text area.north)+(0,-6)$)
        {\input{top}};
    \node[anchor=west]
        at ($(current page text area.north west)
             !.6! % align at a .6 ratio of the top and bottom
             (current page text area.south west)$)
        {\input{left}};
    \node[anchor=east]
        at ($(current page text area.north east)
             !.6!
             (current page text area.south east)$)
        {\input{right}};
    \node[anchor=south]
        at (current page text area.south)
        {\input{bottom}};

    \node at ($(current page text area.west)+(1,8)$)
        {\itshape Haut (graves)};
\end{tikzpicture}

\end{document}

picture of the output of the entire document

8
  • 1
    Yes, my problem was mainely on the left side, but your explaiantion and the idea to create separate classes helps a lot ! Do you have any idea to add the text on the top of the page ?
    – zaord
    Dec 1, 2020 at 17:06
  • I have updated my answer with code to create the image on the left. It is not perfect, but it’s a start. What text do you mean? The ‘Systeme le tron’? I will try to add something for that too when I have time :-)
    – bp99
    Dec 1, 2020 at 19:56
  • Oh Wow ! Thanks A lot ! If I could help you in return ... :) My question is how it is possible to combine theese two code in one file, like positionning one block in front to one other ? Merci :)
    – zaord
    Dec 4, 2020 at 9:40
  • I tried to put the things together but I did not manage to to it, I will wait for your answer ! Thanks
    – zaord
    Dec 7, 2020 at 16:02
  • Hey, sorry for the late reply. I am working on my thesis and the deadline is ridiculously close so unfortunately I am unable to invest any more time in this at the moment. I do plan to get back to it later though!
    – bp99
    Dec 8, 2020 at 13:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.