@cindex instrument names, centering
-If you wish to center the instrument names, you must center all of
-them individually:
+As instrument names are centered by default, multi line names
+are better entered using @code{\center-align}:
@lilypond[quote,verbatim,ragged-right]
{ <<
\new Staff {
- \set Staff.instrumentName = \markup {
- \center-align { "Clarinetti"
- \line { "in B" \smaller \flat } } }
+ \set Staff.instrumentName = \markup \center-align {
+ Clarinetti
+ \line { "in B" \smaller \flat }
+ }
c''1
}
\new Staff {
- \set Staff.instrumentName =
- \markup{ \center-align { Vibraphone }}
+ \set Staff.instrumentName = "Vibraphone"
c''1
}
>>
For longer instrument names, it may be useful to increase the
@code{indent} setting in the @code{\layout} block.
-To center instrument names while leaving extra space to the right,
-
-@lilypond[quote,verbatim,ragged-right]
-\new StaffGroup \relative
-<<
- \new Staff {
- \set Staff.instrumentName =
- \markup { \hcenter-in #10 "blabla" }
- c1 c1
- }
- \new Staff {
- \set Staff.instrumentName =
- \markup { \hcenter-in #10 "blo" }
- c1 c1
- }
->>
-@end lilypond
+Short instrument names, printed before the systems following the first
+one, are also centered by default, in a space which width is given by
+the @code{short-indent} variable of the @code{\layout} block.
To add instrument names to other contexts (such as
@code{GrandStaff}, @code{ChoirStaff}, or @code{StaffGroup}), the
--- /dev/null
+\header {
+
+ texidoc = "Instrument names horizontal alignment is tweaked by
+changing the @code{Staff.Instrument #'self-alignment-X} property. The
+@code{\layout} variables @code{indent} and @code{short-indent} define
+the space where the instrument names are aligned before the first and
+the following systems, respectively."
+
+}
+
+\version "2.11.39"
+\paper { left-margin = 3\cm }
+\score {
+ \new StaffGroup <<
+ \new Staff {
+ \override Staff . InstrumentName #'self-alignment-X = #LEFT
+ \set Staff . instrumentName = \markup \column {
+ "Left aligned" "instrument name"
+ }
+ \set Staff . shortInstrumentName = "Left"
+ c''1 \break c''
+ }
+ \new Staff {
+ \override Staff . InstrumentName #'self-alignment-X = #CENTER
+ \set Staff . instrumentName = \markup \center-align {
+ "Centered" "instrument name"
+ }
+ \set Staff . shortInstrumentName = "Centered"
+ g'1 g'
+ }
+ \new Staff {
+ \override Staff . InstrumentName #'self-alignment-X = #RIGHT
+ \set Staff . instrumentName = \markup \column \right-align {
+ "Right aligned" "instrument name"
+ }
+ \set Staff . shortInstrumentName = "Right"
+ e' \break e'
+ }
+ >>
+ \layout {
+ ragged-right = ##t
+ indent = 4\cm
+ short-indent = 2\cm
+ }
+}
SCM align_y = me_grob->get_property ("self-alignment-Y");
if (scm_is_number (align_y))
p->align_to (Y_AXIS, robust_scm2double (align_y, 0.0));
- return *p;
+
+ /* Horizontal alignment according to the self-alignment-X property
+ * and indent value. */
+ Output_def *layout = me_grob->layout ();
+ Real indent;
+ if (me->get_break_index () == 0)
+ indent = robust_scm2double (layout->c_variable ("indent"), 0);
+ else
+ indent = robust_scm2double (layout->c_variable ("short-indent"), 0);
+ Real align_x = robust_scm2double (me->get_property ("self-alignment-X"), 0);
+ Interval p_extent_x = p->extent (X_AXIS);
+ Interval padding (0.0, max (0.0, indent - p_extent_x.length ()));
+ Real right_padding = padding.length () - padding.linear_combination (align_x);
+ Box box (Interval (p_extent_x[LEFT], p_extent_x[RIGHT] + right_padding),
+ p->extent (Y_AXIS));
+ Stencil *aligned_p = new Stencil (box, p->expr ());
+ return *aligned_p;
}
return Stencil ();
}
"text "
"long-text "
"self-alignment-Y "
+ "self-alignment-X "
);
(X-offset . ,ly:side-position-interface::x-aligned-side)
(direction . ,LEFT)
(self-alignment-Y . ,CENTER)
+ (self-alignment-X . ,CENTER)
(meta . ((class . Spanner)
(interfaces . (system-start-text-interface
side-position-interface
'(pt mm cm in staff-height staff-space
page-top-space
between-system-space between-system-padding
- line-width indent paper-width paper-height horizontal-shift
+ line-width indent short-indent paper-width paper-height horizontal-shift
staff-space line-thickness ledgerline-thickness
blot-diameter left-margin right-margin)))
(ly:modules-lookup (list m) 'right-margin (* 10 mm))))
(module-define! m 'indent (/ w 14))
+ (module-define! m 'short-indent (* 5 mm))
;; page layout - what to do with (printer specific!) margin settings?