I am writing a songbook and I would like to insert guitar chord diagrams in the appropriate positions above the lyrics of each verse. I have found the musixguit package capable of drawing nice diagrams which I would like to include in my songbook (showing fret numbering for barre chords and possibly tabular notation of the chord) but I am not able to position them in accordance with the lyrics.

\documentclass{article}
\usepackage{musixguit}
\begin{document}
\raiseguitar {14}
\NOtes\guitar {Cm $^7$}{2}x-----\gbarre1\gdot33\gdot52
\guitar G{}o-----\gbarre3\gdot25\gdot35\gdot44\en
*Lyrics of the first *verse...
\end{document}

How to place the diagrams above their intended positions (denoted by asterisks)? Would it be possible to define a new command for in-line insertion of predefined chords into the appropriate positions in lyrics like in the following example?

\chord{Cm7}Lyrics of the first \chord{G}verse...

Thank you.

  • 1
    It seems the word above which there's a chord should be the second argument of the \chord command. – Bernard Aug 14 '16 at 22:06
  • Oh, thank you. I didn't really think of adding any more parameters to the command. They are, however, centered above the position (instead of starting there with their left edge) and are drown over previous chords if two diagrams are placed too close to each other (instead of making a horizontal spacing in the lyrics). Could you please think of any correction, preferably to be inserted right into the lyrics? – Kyselejsyreček Aug 14 '16 at 22:16
  • 1
    I've just taken a look at the documentation (but iI don't speak German…); in the example on page 2, the chord is not really centred w.r.t. the word below. There's only a slight shifting from the left side of the word, and there doesn't seem to be any parameter that can change that. If you really want to have the vertical alignment on the left side of the word, you can try with the \stackon command from the stackengine package. – Bernard Aug 14 '16 at 22:43
  • 1
    You are using the musixgui extension from musixtex (which is loaded by the musixguit package). I suggest you have a look at gchords instead – maybe in combination with guitar. – clemens Aug 15 '16 at 7:54
  • 1
    musixgui is only meant for using chord diagrams over music staffs… – clemens Aug 15 '16 at 8:27
up vote 4 down vote accepted

The chords only have to be defined via \guitarchord once, and can be reutilized as needed. Rather that using \raiseguitar to set the vertical position, I use \setstackgap{L}{<baselinekip of stack>} to do so.

EDITED to address deficiencies noted by OP. Macros to use include

\guitarchord\<chordname>{<chord-definition>}

and

\showchord [<short entry text>]{\<chordname>}

where the optional argument is used if the chord text is shorter than the chord width. Note two lengths specified in the MWE that allow adjustments in alignment and minimum chord spacing.

RE-EDITED to provide optional syntax that some may find preferable:

\chordline{\<chordname>}{<text>}

Here is the MWE:

\documentclass{article}
\usepackage{musixguit,stackengine}
\def\chordalign{\dimexpr2.2ex}% 2.2ex sets alignment of chord
\def\chordminwidth{\dimexpr6.5ex}% 6.5ex provides min. hskip for optional argument
\newcommand\guitarchord[2]{%
  \savestack#1{\kern\chordalign\NOtes\guitar #2\en}
}
\newcommand\showchord[2][\relax]{%
  \ifx\relax#1\relax\def\tmpuaw{T}\else\def\tmpuaw{F}\fi%
  \stackengine{\Lstackgap}{#1}{%
    \makebox[0ex][l]{#2}\kern\chordminwidth}{O}{l}{F}{\tmpuaw}{L}%
}
\newcommand\chordline[2]{\setbox0=\hbox{#2}%
  \ifdim\wd0>\chordminwidth\showchord{#1}#2\else\showchord[#2]{#1}\fi%
}
\raiseguitar {0}
\setstackgap{L}{2.7\baselineskip}
\begin{document}
\guitarchord\Cm{{Cm $^7$}{2}x-----\gbarre1\gdot33\gdot52}
\guitarchord\GM{G{}o-----\gbarre3\gdot25\gdot35\gdot44}
\showchord[Ly-]{\Cm} \showchord{\GM}rics of the first 
  \showchord[of 2]{\Cm} \showchord{\GM}verses ...

Alternative syntax:

\chordline{\Cm}{Ly-}
\chordline{\GM}{rics of the first}
\chordline{\Cm}{of 2}
\chordline{\GM}{verses ...}
\end{document}

enter image description here

While I don't recommend it because of potential danger, the OP followed up asking if the # character (and things like parentheses) could be incorporated into chord names. To do so, I make # catcode 11, and employ a lot of \csname nomenclature.

Here is such a version:

\documentclass{article}
\usepackage{musixguit,stackengine}
\def\chordalign{\dimexpr2.2ex}% 2.2ex sets alignment of chord
\def\chordminwidth{\dimexpr9ex}% 6.5ex provides min. hskip for optional argument
\newcommand\guitarchord[2]{%
  \expandafter\savestack\expandafter{\csname #1\endcsname}{%
    \kern\chordalign\NOtes\guitar #2\en}
}
\newcommand\showchord[2][\relax]{%
  \ifx\relax#1\relax\def\tmpuaw{T}\else\def\tmpuaw{F}\fi%
  \stackengine{\Lstackgap}{#1}{%
    \makebox[0ex][l]{\csname #2\endcsname}\kern\chordminwidth}%
    {O}{l}{F}{\tmpuaw}{L}%
}
\newcommand\chordline[2]{\setbox0=\hbox{#2}%
  \ifdim\wd0>\chordminwidth\relax\showchord{#1}#2\else
    \showchord[#2]{#1}\fi%
}
\raiseguitar {0}
\setstackgap{L}{2.7\baselineskip}
\begin{document}
\catcode`#=11
\guitarchord{F#m7(add4)}{{F$\sharp$m7(add4)$^7$}{2}x-----\gbarre1\gdot33\gdot52}
\guitarchord{GM}{G{}o-----\gbarre3\gdot25\gdot35\gdot44}
\showchord[Ly-]{F#m7(add4)} \showchord{GM}rics of the first 
  \showchord[of 2]{F#m7(add4)} \showchord{GM}verses ...

Alternative syntax:

\chordline{F#m7(add4)}{Ly-}
\chordline{GM}{rics of the first}
\chordline{F#m7(add4)}{of 2}
\chordline{GM}{verses ...}
\end{document}

enter image description here

  • This was a nice answer! However, I struggle with the right positioning of the diagrams. They should be aligned to left, not center, starting at the position where they are placed. Also, they should not overflow other diagrams if they appear too close to them but rather shift the lyrics to the right, widening the space between the two words or syllables. It is also sometimes needed to specify only a syllable (or even a one-character space) which the chord should be fixed to. Like e.g. \tclap[0pt]{\Cm}{Ly}\tclap[0pt]{\G}{rics} of the first (...) – Kyselejsyreček Aug 15 '16 at 15:54
  • I have now fixed the alignment issue by updating some definitions from musixgui.tex file (which is rather an ugly hack than a solution). Namely: \def\guitar#1#2#3#4#5#6#7#8{\zchar\r@gu{\raise\Interligne\rlap{#1}% \mxsps\rlap\sixt@@n\rlap{\d@c#3\d@c#4\d@c#5\d@c#6\d@c#7\d@c#8}% \lower\Internote\llap{\eightbf#2\kern\s@v@n\guitar@dim}}}, \def\gbarre#1{\zchar\r@gu{\n@v#1\advance\n@v\m@ne \raise\n@v\guitar@dim\rlap{\mxsps\char18}}} and \def\gdot#1#2{\zchar\r@gu{\n@v#2\advance\n@v\m@ne\kern\guitar@dim \kernm#1\guitar@dim\raise\n@v\guitar@dim\llap{\mxsps\char17}}}. – Kyselejsyreček Aug 15 '16 at 19:05
  • But the diagram overlapping, as can be shown using \frame{\guitar{...}}, is caused by the diagram having no width and this is something I cannot fix on my own. – Kyselejsyreček Aug 15 '16 at 19:08
  • @Kyselejsyreček There are 3 macros in the stackengine package for top lapping, \tllap, \tclap, and \trlap, depending on which alignment is desired (l,c,r). – Steven B. Segletes Aug 15 '16 at 19:15
  • Yes, I have tried all three of them but they have no effect on the diagram placement. – Kyselejsyreček Aug 15 '16 at 19:19

A combination of the guitarchordschemes package (needs v0.7) for creating the chord diagrams and the leadsheets package for placing the chords:

enter image description here

\documentclass{article}
\usepackage[T1]{fontenc}

% the `chords' library of the leadsheets package provides the convenient
% \chord macro; we don't any other functionality  of said package so we
% use the `chords' option:
\usepackage{leadsheets}
% no parsing of the chord input:
\setleadsheets{chord-cs=}

\usepackage{guitarchordschemes}
% guitarchordschemes setup:
\setchordscheme{
  tuning = {,,,,,} ,
  chord-frets = 4 ,
  rotate = -90 ,
  x-unit = 1.5mm , y-unit = 2mm ,
  finger-radius = .25 ,
  line-width = .6pt ,
  restrict-bounding-box ,
  position-format+ = \footnotesize ,
  chord-name-cs = \chordname ,
  name-distance = 0pt
}

\newcommand\minorsevenAtype[2]{%
  \chordscheme[
    name = #1 ,
    position = #2 ,
    finger = {2/2,3/4} ,
    barre = {1/1-5} ,
    mute = {6}
  ]%
}

\newcommand\minorsevenEtype[2]{%
  \chordscheme[
    name = #1 ,
    position = #2 ,
    finger = {1/6} ,
    barre = {1/2-4} ,
    mute = {1,5}
  ]%
}

\newcommand\majorEtype[2]{%
  \chordscheme[
    name = #1 ,
    position = #2 ,
    finger = {2/3,3/4,3/5} ,
    barre = {1/1-6}
  ]%
}

\newcommand\majorAtype[2]{%
  \chordscheme[
    name = #1 ,
    position = #2 ,
    finger = {3/2,3/3,3/4} ,
    barre = {1/1-5} ,
    mute = 6
  ]%
}

\newcommand\cminorseven{\minorsevenAtype{Cmi7}{III}}
\newcommand\fminorseven{\minorsevenEtype{Fmi7}{I}}
\newcommand\gmajor{\majorEtype{Gma}{III}}
\newcommand\ebmajor{\majorAtype{Ebma}{VI}}

\begin{document}

\chord{\cminorseven}Text and text and \chord{\ebmajor}more text and
\chord{\gmajor}more text and even \chord{\fminorseven}more text

\end{document}

Your Answer

 

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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