TransWikia.com

Accordion Keyboard layout with TikZ

TeX - LaTeX Asked by zaord on May 9, 2021

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

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 !

One Answer

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
    ]{%
        majnodepart{lower}min
        & majnodepart{lower}maj
        & majnodepart{lower}min
        
        SInodepart{lower}DOsh
        & MIflnodepart{lower}SIfl
        & SOLshnodepart{lower}SI
        

        majnodepart{lower}min
        & majnodepart{lower}min
        & majnodepart{lower}maj
        
        LAnodepart{lower}FAsh
        & MIflnodepart{lower}LA
        & SOLshnodepart{lower}RE
        

        majnodepart{lower}maj
        & |[circle,minimum width=1.5cm,minimum height=1.5cm]|
          maj
        & majnodepart{lower}maj
        
        REnodepart{lower}DO
        & |[circle,minimum width=1.5cm,minimum height=1.5cm]|
          FA
        & DOshnodepart{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) {DOshnodepart{lower}MIfl};
    foreach t/b/n in {%
        RÉ/FAsh/2,SOL/LA/3,SI/DO/4,RÉ/MI/5,SOL/FAsh/6,
        SI/LA/7,RÉ/DO/8,SOL/MI/9,SI/FAsh/10,RÉ/LAsh/11,
        SOL/DO/12
    } node[%
        accord,on chain=1,label={[lb]above:n}
    ] {tnodepart{lower}b};

    node[%
        accord,on chain=2,below right=-2.5mm and 8mm of L,
        label={[lb]above:{1'}}
    ] (M) {LAnodepart{lower}SOLsh};
    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'}}
    ] {tnodepart{lower}b};

    node[%
        accord,on chain=3,below right=-2.5mm and 8mm of M,
        label={[lb]above:{1''}}
    ] {SOLshnodepart{lower}SIfl};
    foreach t/b/n in {%
        SIfl/DOsh/2,MIfl/SOL/3,SOLsh/SOLsh/4,SIfl/SIfl/5,
        MIfl/DOsh/6,SOLsh/SOL/7,SIfl/SOLsh/8,MIfl/SIfl/9,
        SOLsh/DOsh/10
    } node[%
        accord,on chain=3,label={[lb]above:{n''}}
    ] {tnodepart{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
newcommanddrawtitle{%
    noindent
    bgroup% so that arraystretch only applies here
    defarraystretch{2}
    begin{tabular}{l|p{6cm}}
        multirow{4}{*}{%
            begin{turn}{90}
                Largebfseries Plan de clavier
            end{turn}
        }
        & {Largebfseries 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

Answered by bp99 on May 9, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP