Generating ukulele chord diagrams

Edit: Here is a better \drawukulelechord macro using TikZ.

  • The \drawukulelechord macro draws a ukulele chord. Its mandatory argument is a list of four numbers (for four strings) : -1 (string is not played), 0 (opened string), 1 and above (finger position for this string). The optional argument may be used to change scale (default: x=2ex and y=2ex).

  • The \defineukulelechord macro allows to associate a name (first argument) and a list to use with \drawukulelechord (second argument).

  • The \ukulelechord macro draws a named ukulele chord (predefined by \defineukulelechord).

You may uncomment or comment the line with % opened string to explicitly draw or not an opened string.

enter image description here

\documentclass{standalone}
\usepackage{etoolbox}
\usepackage{tikz}
\newcommand\drawukulelechord[2][]{%
  \edef\chord{#2}%
  \begin{tikzpicture}[x=2ex,y=2ex,line cap=round,line width=.4pt,
    baseline=(current bounding box.center),#1]
    \draw[line width=.6pt] (1,0) -- (4,0);
    \foreach \d in {1,...,4}{\draw (1,-\d) -- (4,-\d);}
    \foreach \d[count=\p] in \chord {
      \draw (\p,0) -- (\p,-4.5);
      \ifdefstring{\d}{-1}{
        \draw (\p,.25) +(-.125,-.125) -- +(.125,.125)
        +(-.125,.125) -- +(.125,-.125);
      }{
        \ifdefstring{\d}{0}{
          \draw (\p,.25) circle(.125); % opened string
        }{
          \fill (\p,.5-1*\d) circle(.25);
        }
      }
    }
    \path[use as bounding box] (0.5,.5) rectangle (4.5,-5);
  \end{tikzpicture}%
}
\makeatletter
\newcommand\defineukulelechord[2]{%
  \csdef{@ukulelechord@#1}{\drawukulelechord{#2}}%
}
\newcommand\ukulelechord[1]{%
  \ifcsdef{@ukulelechord@#1}{%
    \csuse{@ukulelechord@#1}%
  }{%
    \GenericError{}{Undefined ukulele chord '#1'}{}{}% 
  }%
}
\makeatother

\defineukulelechord{A maj}{2,1,0,0}
\defineukulelechord{A 6}{2,1,2,0}
\defineukulelechord{G sharp maj}{5,3,4,3}
\defineukulelechord{A flat maj}{5,3,4,3}
\defineukulelechord{G sharp 6}{1,3,1,3}

\begin{document}
\begin{tabular}{rcc}
                     & maj                         & 6                        \\
  A                  & \ukulelechord{A maj}        & \ukulelechord{A 6}     \\
  G$\sharp$/A$\flat$ & \ukulelechord{G sharp maj}  & \ukulelechord{G sharp 6} \\
  Test               & \drawukulelechord{-1,0,1,2} & \drawukulelechord{2,-1,-1,-1}
\end{tabular}
\end{document}

The package guitarchordschemes can be used for this – at least with v0.7. Starting with said version it allows for setting the string number and for rotating the scheme.

In the following example I also use the chords library of the leadsheets package for typesetting of the chord names. This is just for convenience and not an essential part of the example.

enter image description here

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage[margin=2cm]{geometry}

\usepackage{guitarchordschemes}
% the `chords' library of the leadsheets package provides the convenient
% \writechord macro; we don't any other functionality  of said package so we
% use the `chords' option:
\usepackage[chords]{leadsheets}

\usepackage{array}

% guitarchordschemes setup:
\setchordscheme{
  strings = 4 ,
  chord-frets = 5 ,
  tuning = {,,,} ,
  rotate = -90 ,
  x-unit = 1.333mm , y-unit = 2mm ,
  finger-radius = .25 ,
  line-width = .6pt ,
  restrict-bounding-box
}

\begin{document}

\begin{tabular}{l*{13}{c}}
  & ma & 6 & 7 & 9 & maj7 & mi & mi6 & mi7 & mi9 & sus2 & sus4 & aug & dim \\
  \writechord{A} &
  \chordscheme[ finger = {2/4,1/3} ] &
  \chordscheme[ finger = {2/4,1/3,2/2} ] &
  \chordscheme[ finger = {1/3} ] &
  \chordscheme[ finger = {1/3,2/1} ] &
  \chordscheme[ finger = {1/4,1/3} ] &
  \chordscheme[ finger = {2/4} ] &
  \chordscheme[ finger = {2/4,2/2} ] &
  \chordscheme &
  \chordscheme[ finger = {2/4,2/1} ] &
  \chordscheme[ finger = {2/4,4/3,5/2,2/1} ] &
  \chordscheme[ finger = {2/4,2/3} ] &
  \chordscheme[ finger = {2/4,1/3,1/2} ] &
  \chordscheme[ finger = {2/4,3/3,2/2,3/1} ] \\
  \writechord{A#}\slash\writechord{Bb} &
  \chordscheme[ finger = {3/4,2/3,1/2,1/1} ] &
  \chordscheme[ finger = {2/3,1/2,1/1} ] &
  \chordscheme[ finger = {1/4,2/3,1/2,1/1} ] &
  \chordscheme[ finger = {1/4,2/3,1/2,3/1} ] &
  \chordscheme[ finger = {3/4,2/3,1/2} ] &
  \chordscheme[ finger = {3/4,1/3,1/2,1/1} ] &
  \chordscheme[ finger = {3/4,1/3,3/2,1/1} ] &
  \chordscheme[ finger = {1/4,1/3,1/2,1/1} ] &
  \chordscheme[ finger = {3/4,1/3,1/2,3/1} ] &
  \chordscheme[ finger = {3/4,1/2,1/1} ] &
  \chordscheme[ finger = {3/4,3/3,1/2,1/1} ] &
  \chordscheme[ finger = {3/4,2/3,2/2,1/1} ] &
  \chordscheme[ finger = {1/3,1/1} ] \\
  \writechord{B} &
  \chordscheme[ finger = {4/4,3/3,2/2,2/1} ] &
  \chordscheme[ finger = {1/4,3/3,2/2,2/1} ] &
  \chordscheme[ finger = {2/4,3/3,2/2,2/1} ] &
  \chordscheme[ finger = {2/4,3/3,2/2,4/1} ] &
  \chordscheme[ finger = {4/4,3/3,2/2,1/1} ] &
  \chordscheme[ finger = {4/4,2/3,2/2,2/1} ] &
  \chordscheme[ finger = {1/4,2/3,2/2,2/1} ] &
  \chordscheme[ finger = {2/4,2/3,2/2,2/1} ] &
  \chordscheme[ finger = {4/4,2/3,2/2,4/1} ] &
  \chordscheme[ finger = {4/4,1/3,2/2,2/1} ] &
  \chordscheme[ finger = {4/4,4/3,2/2,2/1} ] &
  \chordscheme[ finger = {3/3,3/2,2/1} ] &
  \chordscheme[ finger = {1/4,2/3,1/2,2/1} ] \\
  \writechord{C} &
  \chordscheme[ finger = {3/1} ] &
  \chordscheme &
  \chordscheme[ finger = {1/1} ] &
  \chordscheme[ finger = {2/3,1/1} ] &
  \chordscheme[ finger = {2/1} ] &
  \chordscheme[ finger = {3/3,3/2,3/1} ] &
  \chordscheme[ finger = {3/3,3/2} ] &
  \chordscheme[ finger = {3/4,3/3,3/2,3/1} ] &
  \chordscheme[ finger = {5/4,3/3,3/2,5/1} ] &
  \chordscheme[ finger = {2/3,3/2,3/1} ] &
  \chordscheme[ finger = {1/2,3/1} ] &
  \chordscheme[ finger = {1/4,3/1} ] &
  \chordscheme[ finger = {2/4,3/3,2/2,3/1} ] \\
  \writechord{C#}\slash\writechord{Db} &
  \chordscheme[ finger = {1/4,1/3,1/2,4/1} ] &
  \chordscheme[ finger = {1/4,1/3,1/2,1/1} ] &
  \chordscheme[ finger = {1/4,1/3,1/2,2/1} ] &
  \chordscheme[ finger = {1/4,3/3,1/2,2/1} ] &
  \chordscheme[ finger = {1/4,1/3,1/2,3/1} ] &
  \chordscheme[ finger = {5/4,3/3,3/2,3/1} ] &
  \chordscheme[ finger = {1/4,4/3,4/2,1/1} ] &
  \chordscheme[ finger = {1/4,4/3,4/2,2/1} ] &
  \chordscheme[ finger = {1/4,3/3,4/1} ] &
  \chordscheme[ finger = {1/4,3/3,4/2,4/1} ] &
  \chordscheme[ finger = {1/4,1/3,2/2,4/1} ] &
  \chordscheme[ finger = {2/4,1/3,1/2} ] &
  \chordscheme[ finger = {1/3,1/1} ] \\
  \writechord{D} &
  \chordscheme[ finger = {2/4,2/3,2/2} ] &
  \chordscheme[ finger = {2/4,2/3,2/2,2/1} ] &
  \chordscheme[ finger = {2/4,2/3,2/2,3/1} ] &
  \chordscheme[ finger = {2/4,4/3,2/2,3/1} ] &
  \chordscheme[ finger = {2/4,2/3,2/2,4/1} ] &
  \chordscheme[ finger = {2/4,2/3,1/2} ] &
  \chordscheme[ finger = {2/4,2/3,1/2,2/1} ] &
  \chordscheme[ finger = {2/4,2/3,1/2,3/1} ] &
  \chordscheme[ finger = {2/4,4/3,1/2,5/1} ] &
  \chordscheme[ finger = {2/4,2/3} ] &
  \chordscheme[ finger = {2/3,3/2} ] &
  \chordscheme[ finger = {3/4,2/3,2/2,1/1} ] &
  \chordscheme[ finger = {1/4,2/3,1/2,2/1} ] \\
  \writechord{D#}\slash\writechord{Eb} &
  \chordscheme[ finger = {3/3,3/2,1/1} ] &
  \chordscheme[ finger = {3/4,3/3,3/2,3/1} ] &
  \chordscheme[ finger = {3/4,3/3,3/2,4/1} ] &
  \chordscheme[ finger = {1/3,1/2,1/1} ] &
  \chordscheme[ finger = {3/4,3/3,3/2,5/1} ] &
  \chordscheme[ finger = {3/4,3/3,2/2,1/1} ] &
  \chordscheme[ finger = {3/4,2/2,1/1} ] &
  \chordscheme[ finger = {3/4,1/3,2/2,1/1} ] &
  \setchordscheme{ chord-frets = 6 }\chordscheme[ finger = {3/4,5/3,2/2,6/1} ] &
  \chordscheme[ finger = {3/4,3/3,1/2,1/1} ] &
  \chordscheme[ finger = {1/4,3/3,4/2,1/1} ] &
  \chordscheme[ finger = {3/3,3/2,2/1} ] &
  \chordscheme[ finger = {2/4,3/3,2/2,3/1} ] \\
  \writechord{E} &
  \chordscheme[ finger = {4/4,4/3,4/2,2/1} ] &
  \chordscheme[ finger = {1/4,1/3,2/1} ] &
  \chordscheme[ finger = {1/4,2/3,2/1} ] &
  \chordscheme[ finger = {1/4,2/3,2/2,2/1} ] &
  \chordscheme[ finger = {1/4,3/3,2/1} ] &
  \chordscheme[ finger = {4/3,3/2,2/1} ] &
  \chordscheme[ finger = {4/4,4/3,3/2,4/1} ] &
  \chordscheme[ finger = {2/3,2/1} ] &
  \chordscheme[ finger = {4/3,2/2,2/1} ] &
  \chordscheme[ finger = {4/4,4/3,2/2,2/1} ] &
  \chordscheme[ finger = {2/4,4/3,5/2,2/1} ] &
  \chordscheme[ finger = {1/4,3/1} ] &
  \chordscheme[ finger = {2/3,2/1} ]
\end{tabular}

\end{document}

Adding to Paul's brilliant answer, I recommend using lilyglyphs. I've created some commands (with the help of the creator of lilyglyphs) making it less cumbersome entering chord symbols.

output

\documentclass{article}
\usepackage{fontspec}
\usepackage{tikz}
\usepackage{lilyglyphs}
\usepackage{xspace}

\newcommand{\tinysharpx}[1][0.10ex]{\hspace*{#1}\sharp[scale=.65,raise=.1]\hspace*{#1}}
\newcommand{\tinyflatx}[1][0.10ex]{\hspace*{#1}\flat[scale=.6,raise=.1]\hspace*{#1}}
\newcommand{\flatx}[1][0.18ex]{\hspace*{#1}\flat\hspace*{#1}}
\newcommand{\sharpx}[1][0.18ex]{\hspace*{#1}\sharp\hspace*{#1}}

\newcommand\bigchord[4]{\(\text{#1}^{#2}\mkern-3mu\relax(\mathop{}\limits\mkern-3mu\relax{}^{#3}_{#4})\)}
\newcommand\chord[2]{\(\text{#1}^{#2}\)}

\newcommand{\aflat}{A\(\flatx\)\xspace}
\newcommand{\bflat}{B\(\flatx\)\xspace}
\newcommand{\cflat}{C\(\flatx\)\xspace}
\newcommand{\dflat}{D\(\flatx\)\xspace}
\newcommand{\eflat}{E\(\flatx\)\xspace}
\newcommand{\fflat}{F\(\flatx\)\xspace}
\newcommand{\gflat}{G\(\flatx\)\xspace}

\newcommand{\aflatm}{A\(\flatx\)m\xspace}
\newcommand{\bflatm}{B\(\flatx\)m\xspace}
\newcommand{\cflatm}{C\(\flatx\)m\xspace}
\newcommand{\dflatm}{D\(\flatx\)m\xspace}
\newcommand{\eflatm}{E\(\flatx\)m\xspace}
\newcommand{\fflatm}{F\(\flatx\)m\xspace}
\newcommand{\gflatm}{G\(\flatx\)m\xspace}

\newcommand{\aiss}{A\(\sharpx\)\xspace}
\newcommand{\biss}{B\(\sharpx\)\xspace}
\newcommand{\ciss}{C\(\sharpx\)\xspace}
\newcommand{\diss}{D\(\sharpx\)\xspace}
\newcommand{\eiss}{E\(\sharpx\)\xspace}
\newcommand{\fiss}{F\(\sharpx\)\xspace}
\newcommand{\giss}{G\(\sharpx\)\xspace}

\newcommand{\aissm}{A\(\sharpx\)m\xspace}
\newcommand{\bissm}{B\(\sharpx\)m\xspace}
\newcommand{\cissm}{C\(\sharpx\)m\xspace}
\newcommand{\dissm}{D\(\sharpx\)m\xspace}
\newcommand{\eissm}{E\(\sharpx\)m\xspace}
\newcommand{\fissm}{F\(\sharpx\)m\xspace}
\newcommand{\gissm}{G\(\sharpx\)m\xspace}

\newcommand\ukulelechord[2][]{%
  \begin{tikzpicture}[x=3mm,y=3mm,line cap=round,line width=.4pt,
    baseline=(current bounding box.center),#1]
    \draw[line width=.6pt] (1,0) -- (4,0);
    \foreach \d in {1,...,4}{\draw (1,-\d) -- (4,-\d);}
    \foreach \d[count=\p] in {#2}{
      \draw (\p,0) -- (\p,-4.5);
      \ifnum\d>0 \fill (\p,.5-1*\d) circle(.8mm); \fi
    }
    \path[use as bounding box] (0.5,.3) rectangle (4.5,-5);
  \end{tikzpicture}%
}
\begin{document}
\begin{tabular}{rcc}
  &maj& 6 \\
  A & \ukulelechord{2,1,0,0} & \ukulelechord{2,1,2,0} \\
  \giss/\aflat & \ukulelechord{5,3,4,5} & \ukulelechord{1,3,1,3} \\
\end{tabular}
\end{document}

Tags:

Music

Diagrams