1 @c -*- coding: utf-8; mode: texinfo; -*-
2 @c This file is part of lilypond.tely
4 @c A menu is needed before every deeper *section nesting of @node's; run
5 @c M-x texinfo-all-menus-update
6 @c to automatically fill in these menus before saving changes
9 @chapter Spacing issues
11 The global paper layout is determined by three factors: the page layout, the
12 line breaks, and the spacing. These all influence each other. The
13 choice of spacing determines how densely each system of music is set.
14 This influences where line breaks are chosen, and thus ultimately, how
15 many pages a piece of music takes.
17 Globally spoken, this procedure happens in three steps: first,
18 flexible distances (``springs'') are chosen, based on durations. All
19 possible line breaking combinations are tried, and the one with the
20 best results -- a layout that has uniform density and requires as
21 little stretching or cramping as possible -- is chosen.
23 After spacing and linebreaking, the systems are distributed across
24 pages, taking into account the size of the page, and the size of the
31 * Horizontal spacing::
33 * Displaying spacing::
38 @section Paper and pages
40 This section deals with the boundaries that define the area
41 that music can be printed inside.
50 @subsection Paper size
56 To change the paper size, there are two commands,
58 #(set-default-paper-size "a4")
60 #(set-paper-size "a4")
64 The first command sets the size of all pages. The second command sets the
66 of the pages that the @code{\paper} block applies to -- if the @code{\paper}
67 block is at the top of the file, then it will apply to all pages. If the
68 @code{\paper} block is inside a @code{\book}, then the paper size will only
71 Support for the following paper sizes are included by default,
72 @code{a6}, @code{a5}, @code{a4}, @code{a3}, @code{legal}, @code{letter},
73 @code{11x17} (also known as tabloid).
75 Extra sizes may be added by editing the definition for
76 @code{paper-alist} in the initialization file @file{scm/paper.scm}.
81 If the symbol @code{landscape} is supplied as an argument to
82 @code{set-default-paper-size}, the pages will be rotated by 90 degrees,
83 and wider line widths will be set correspondingly.
86 #(set-default-paper-size "a6" 'landscape)
89 Setting the paper size will adjust a number of @code{\paper} variables
90 (such as margins). To use a particular paper size with altered
91 @code{\paper} variables, set the paper size before setting the variables.
95 @subsection Page formatting
97 @cindex page formatting
102 LilyPond will do page layout, set margins, and add headers and
103 footers to each page.
105 The default layout responds to the following settings in the
112 @funindex first-page-number
113 @item first-page-number
114 The value of the page number of the first page. Default is@tie{}1.
116 @funindex printfirst-page-number
117 @item printfirst-page-number
118 If set to true, will print the page number in the first page. Default is
121 @funindex print-page-number
122 @item print-page-number
123 If set to false, page numbers will not be printed.
125 @funindex paper-width
127 The width of the page.
129 @funindex paper-height
131 The height of the page.
135 Margin between header and top of the page.
137 @funindex bottom-margin
139 Margin between footer and bottom of the page.
141 @funindex left-margin
143 Margin between the left side of the page and the beginning of the music.
147 The length of the systems.
149 @funindex head-separation
150 @item head-separation
151 Distance between the top-most music system and the page header.
153 @funindex foot-separation
154 @item foot-separation
155 Distance between the bottom-most music system and the page footer.
157 @funindex page-top-space
158 Distance from the top of the printable area to the center of the first
159 staff. This only works for staves which are vertically small. Big staves
160 are set with the top of their bounding box aligned to the top of the
163 @funindex ragged-bottom
165 If set to true, systems will not be spread vertically across the page. This
166 does not affect the last page.
168 This should be set to true for pieces that have only two or three
169 systems per page, for example orchestral scores.
171 @funindex ragged-last-bottom
172 @item ragged-last-bottom
173 If set to false, systems will be spread vertically to fill the last page.
175 Pieces that amply fill two pages or more should have this set to
178 @funindex system-count
180 This variable, if set, specifies into how many lines a score should be
183 @funindex between-system-space
184 @item between-system-space
185 This dimensions determines the distance between systems. It is the
186 ideal distance between the center of the bottom staff of one system
187 and the center of the top staff of the next system.
189 Increasing this will provide a more even appearance of the page at the
190 cost of using more vertical space.
192 @funindex between-system-padding
193 @item between-system-padding
194 This dimension is the minimum amount of white space that will always
195 be present between the bottom-most symbol of one system, and the
196 top-most of the next system.
198 Increasing this will put systems whose bounding boxes almost touch
202 @funindex horizontal-shift
203 @item horizontal-shift
204 All systems (including titles and system separators) are shifted by
205 this amount to the right. Page markup, such as headers and footers are
206 not affected by this. The purpose of this variable is to make space
207 for instrument names at the left.
209 @funindex after-title-space
210 @item after-title-space
211 Amount of space between the title and the first system.
213 @funindex after-title-space
214 @item before-title-space
215 Amount of space between the last system of the previous piece and the
218 @funindex between-title-space
219 @item between-title-space
220 Amount of space between consecutive titles (e.g., the title of the
221 book and the title of a piece).
223 @funindex printallheaders
224 @item printallheaders
225 Setting this to #t will print all headers for each \score in a
226 \book. Normally only the piece and opus \headers are printed.
228 @funindex systemSeparatorMarkup
229 @item systemSeparatorMarkup
230 This contains a markup object, which will be inserted between
231 systems. This is often used for orchestral scores.
233 The markup command @code{\slashSeparator} is provided as a sensible
236 @lilypond[ragged-right]
239 \relative { c1 \break c1 }
242 systemSeparatorMarkup = \slashSeparator
258 ragged-last-bottom = ##t
262 You can also define these values in Scheme. In that case @code{mm},
263 @code{in}, @code{pt}, and @code{cm} are variables defined in
264 @file{paper-defaults.ly} with values in millimeters. That is why the
265 value must be multiplied in the example
269 #(define bottom-margin (* 2 cm))
273 The header and footer are created by the functions @code{make-footer}
274 and @code{make-header}, defined in @code{\paper}. The default
275 implementations are in @file{ly/@/paper@/-defaults@/.ly} and
276 @file{ly/@/titling@/-init@/.ly}.
278 The page layout itself is done by two functions in the
279 @code{\paper} block, @code{page-music-height} and
280 @code{page-make-stencil}. The former tells the line-breaking algorithm
281 how much space can be spent on a page, the latter creates the actual
282 page given the system to put on it.
287 The option right-margin is defined but doesn't set the right margin
288 yet. The value for the right margin has to be defined adjusting the
289 values of @code{left-margin} and @code{line-width}.
291 The default page header puts the page number and the @code{instrument}
292 field from the @code{\header} block on a line.
294 The titles (from the @code{\header@{@}} section) are treated as a
295 system, so @code{ragged-bottom} and @code{ragged-last-bottom} will
296 add space between the titles and the first system of the score.
300 @section Music layout
303 * Setting global staff size::
308 @node Setting global staff size
309 @subsection Setting global staff size
311 @cindex font size, setting
312 @cindex staff size, setting
313 @funindex layout file
315 To set the global staff size, use @code{set-global-staff-size}.
318 #(set-global-staff-size 14)
322 This sets the global default size to 14pt staff height and scales all
325 The Feta font provides musical symbols at eight different
326 sizes. Each font is tuned for a different staff size: at a smaller size
327 the font becomes heavier, to match the relatively heavier staff lines.
328 The recommended font sizes are listed in the following table:
331 @multitable @columnfractions .15 .2 .22 .2
334 @tab @b{staff height (pt)}
335 @tab @b{staff height (mm)}
377 @c modern rental material?
382 These fonts are available in any sizes. The context property
383 @code{fontSize} and the layout property @code{staff-space} (in
384 @internalsref{StaffSymbol}) can be used to tune the size for individual
385 staves. The sizes of individual staves are relative to the global size.
393 This manual: @ref{Selecting notation font size}.
397 @subsection Score layout
401 While @code{\paper} contains settings that relate to the page formatting
402 of the whole document, @code{\layout} contains settings for score-specific
409 \override VerticalAxisGroup #'minimum-Y-extent = #'(-6 . 6)
412 \override TextScript #'padding = #1.0
413 \override Glissando #'thickness = #3
421 This manual: @ref{Changing context default settings}
424 @node Vertical spacing
425 @section Vertical spacing
427 @cindex vertical spacing
428 @cindex spacing, vertical
430 Vertical spacing is controlled by three things: the amount of
431 space available (i.e., paper size and margins), the amount of
432 space between systems, and the amount of space between
433 staves inside a system.
436 * Vertical spacing inside a system::
437 * Vertical spacing of piano staves::
438 * Vertical spacing between systems::
439 * Controlling spacing of individual systems::
443 @node Vertical spacing inside a system
444 @subsection Vertical spacing inside a system
446 @cindex distance between staves
447 @cindex staff distance
448 @cindex space between staves
449 @cindex space inside systems
451 The height of each system is determined automatically. To prevent
452 staves from bumping into each other, some minimum distances are set.
453 By changing these, you can put staves closer together. This
454 reduces the amount of space each system requires, and may result
455 in having more systems per page.
457 Normally staves are stacked vertically. To make staves maintain a
458 distance, their vertical size is padded. This is done with the
459 property @code{minimum-Y-extent}. When applied to a
460 @internalsref{VerticalAxisGroup}, it controls the size of a horizontal
461 line, such as a staff or a line of lyrics. @code{minimum-Y-extent}
462 takes a pair of numbers, so
463 if you want to make it smaller than its default @code{#'(-4 . 4)}
467 \override Staff.VerticalAxisGroup #'minimum-Y-extent = #'(-3 . 3)
471 This sets the vertical size of the current staff to 3 staff spaces on
472 either side of the center staff line. The value @code{(-3 . 3)} is
473 interpreted as an interval, where the center line is the 0, so the
474 first number is generally negative. The numbers need not match;
475 for example, the staff can be made larger at the bottom by setting
476 it to @code{(-6 . 4)}.
481 Internals: Vertical alignment of staves is handled by the
482 @internalsref{VerticalAlignment} object. The context parameters
483 specifying the vertical extent are described in connection with
484 the @internalsref{Axis_group_engraver}.
486 Example files: @inputfileref{input/regression/,page-spacing.ly},
487 @inputfileref{input/regression/,alignment-vertical-spacing.ly}.
490 @node Vertical spacing of piano staves
491 @subsection Vertical spacing of piano staves
493 The distance between staves of a @internalsref{PianoStaff} cannot be
494 computed during formatting. Rather, to make cross-staff beaming work
495 correctly, that distance has to be fixed beforehand.
497 The distance of staves in a @code{PianoStaff} is set with the
498 @code{forced-distance} property of the
499 @internalsref{VerticalAlignment} object, created in
500 @internalsref{PianoStaff}.
502 It can be adjusted as follows
504 \new PianoStaff \with @{
505 \override VerticalAlignment #'forced-distance = #7
512 This would bring the staves together at a distance of 7 staff spaces,
513 measured from the center line of each staff.
515 The difference is demonstrated in the following example,
516 @lilypond[quote,verbatim]
518 \new PianoStaff \with {
519 \override VerticalAlignment #'forced-distance = #7
534 Example files: @inputfileref{input/regression/,alignment-vertical-spacing.ly}.
537 @node Vertical spacing between systems
538 @subsection Vertical spacing between systems
540 Space between systems are controlled by four @code{\paper} variables,
544 between-system-space = 1.5\cm
545 between-system-padding = #1
547 ragged-last-bottom=##f
552 @node Controlling spacing of individual systems
553 @subsection Controlling spacing of individual systems
555 It is also possible to change the distance between for each system
556 individually. This is done by including the command
560 #"Score.NonMusicalPaperColumn"
561 #'line-break-system-details
562 #'((fixed-alignment-extra-space . 15))
566 at the line break before the system to be changed. The distance
567 @code{15} is distributed over all staves that have a fixed distance
568 alignment. For example,
570 @lilypond[ragged-right, fragment, relative=2, staffsize=13]
576 #"Score.NonMusicalPaperColumn"
577 #'line-break-system-details
578 #'((fixed-alignment-extra-space . 15))
586 The distance for @code{fixed-alignment-extra-space} may also be
591 @node Horizontal spacing
592 @section Horizontal Spacing
594 @cindex horizontal spacing
595 @cindex spacing, horizontal
598 * Horizontal spacing overview::
599 * Changing horizontal spacing::
604 @node Horizontal spacing overview
605 @subsection Horizontal spacing overview
607 The spacing engine translates differences in durations into stretchable
608 distances (``springs'') of differring lengths. Longer durations get
609 more space, shorter durations get less. The shortest durations get a
610 fixed amount of space (which is controlled by
611 @code{shortest-duration-space} in the @internalsref{SpacingSpanner}
612 object). The longer the duration, the more space it gets: doubling a
613 duration adds a fixed amount (this amount is controlled by
614 @code{spacing-increment}) of space to the note.
616 For example, the following piece contains lots of half, quarter, and
617 8th notes; the eighth note is followed by 1 note head width (NHW).
618 The quarter note is followed by 2 NHW, the half by 3 NHW, etc.
620 @lilypond[quote,fragment,verbatim,relative=1]
621 c2 c4. c8 c4. c8 c4. c8 c8
625 Normally, @code{spacing-increment} is set to 1.2 staff space, which is
626 approximately the width of a note head, and
627 @code{shortest-duration-space} is set to 2.0, meaning that the
628 shortest note gets 2.4 staff space (2.0 times the
629 @code{spacing-increment}) of horizontal space. This space is counted
630 from the left edge of the symbol, so the shortest notes are generally
631 followed by one NHW of space.
633 If one would follow the above procedure exactly, then adding a single
634 32nd note to a score that uses 8th and 16th notes, would widen up the
635 entire score a lot. The shortest note is no longer a 16th, but a 32nd,
636 thus adding 1 NHW to every note. To prevent this, the shortest
637 duration for spacing is not the shortest note in the score, but rather
638 the one which occurs most frequently.
641 The most common shortest duration is determined as follows: in every
642 measure, the shortest duration is determined. The most common shortest
643 duration is taken as the basis for the spacing, with the stipulation
644 that this shortest duration should always be equal to or shorter than
645 an 8th note. The shortest duration is printed when you run
646 @code{lilypond} with the @code{--verbose} option.
648 These durations may also be customized. If you set the
649 @code{common-shortest-duration} in @internalsref{SpacingSpanner}, then
650 this sets the base duration for spacing. The maximum duration for this
651 base (normally an 8th), is set through @code{base-shortest-duration}.
653 @funindex common-shortest-duration
654 @funindex base-shortest-duration
655 @funindex stem-spacing-correction
658 Notes that are even shorter than the common shortest note are
659 followed by a space that is proportional to their duration relative to
660 the common shortest note. So if we were to add only a few 16th notes
661 to the example above, they would be followed by half a NHW:
663 @lilypond[quote,fragment,verbatim,relative=2]
664 c2 c4. c8 c4. c16[ c] c4. c8 c8 c8 c4 c4 c4
668 In the introduction (see @ref{Engraving}), it was explained that stem
669 directions influence spacing. This is controlled with the
670 @code{stem-spacing-correction} property in the
671 @internalsref{NoteSpacing}, object. These are generated for every
672 @internalsref{Voice} context. The @code{StaffSpacing} object
673 (generated in @internalsref{Staff} context) contains the same property
674 for controlling the stem/bar line spacing. The following example shows
675 these corrections, once with default settings, and once with
676 exaggerated corrections:
678 @lilypond[quote,ragged-right]
682 \override Staff.NoteSpacing #'stem-spacing-correction = #1.5
683 \override Staff.StaffSpacing #'stem-spacing-correction = #1.5
689 Proportional notation is supported; see @ref{Proportional notation}.
694 Internals: @internalsref{SpacingSpanner}, @internalsref{NoteSpacing},
695 @internalsref{StaffSpacing}, @internalsref{SeparationItem}, and
696 @internalsref{SeparatingGroupSpanner}.
701 There is no convenient mechanism to manually override spacing. The
702 following work-around may be used to insert extra space into a score.
704 \once \override Score.SeparationItem #'padding = #1
707 No work-around exists for decreasing the amount of space.
710 @c FIXME: include this in 2.9; currently removed for 2.8 -gp
712 @node New spacing area
713 @subsection New spacing area
715 New sections with different spacing parameters can be started with
716 @code{newSpacingSection}. This is useful when there are
717 sections with a different notions of long and short notes.
719 In the following example, the time signature change introduces a new
720 section, and hence the 16ths notes are spaced wider.
722 @li lypond[relative,fragment,verbatim,quote]
725 c8 c c4 c16[ c c8] c4
732 @node Changing horizontal spacing
733 @subsection Changing horizontal spacing
735 Horizontal spacing may be altered with the
736 @code{base-shortest-duration} property. Here
737 we compare the same music; once without altering
738 the property, and then altered. Larger values
739 of @code{ly:make-moment} will produce smaller
742 @lilypond[relative,verbatim,line-width=12\cm]
745 g4 e e2 | f4 d d2 | c4 d e f | g4 g g2 |
746 g4 e e2 | f4 d d2 | c4 e g g | c,1 |
747 d4 d d d | d4 e f2 | e4 e e e | e4 f g2 |
748 g4 e e2 | f4 d d2 | c4 e g g | c,1 |
753 @lilypond[relative,verbatim,line-width=12\cm]
756 g4 e e2 | f4 d d2 | c4 d e f | g4 g g2 |
757 g4 e e2 | f4 d d2 | c4 e g g | c,1 |
758 d4 d d d | d4 e f2 | e4 e e e | e4 f g2 |
759 g4 e e2 | f4 d d2 | c4 e g g | c,1 |
764 \override SpacingSpanner
765 #'base-shortest-duration = #(ly:make-moment 1 4)
774 By default, spacing in tuplets depends on various non-duration
775 factors (such as accidentals, clef changes, etc). To disregard
776 such symbols and force uniform equal-duration spacing, use
777 @code{Score.SpacingSpanner #'uniform-stretching}. This
778 property can only be changed at the beginning of a score,
780 @lilypond[quote,ragged-right,relative=2,fragment,verbatim]
782 \override SpacingSpanner #'uniform-stretching = ##t
800 When @code{strict-note-spacing} is set, notes are spaced without
801 regard for clefs, bar lines, and grace notes,
803 @lilypond[quote,ragged-right,relative=2,fragment,verbatim]
804 \override Score.SpacingSpanner #'strict-note-spacing = ##t
805 \new Staff { c8[ c \clef alto c \grace { c16[ c] } c8 c c] c32[ c32] }
810 @subsection Line length
813 @cindex breaking pages
817 @funindex ragged-right
818 @funindex ragged-last
820 @c Although line-width can be set in \layout, it should be set in paper
821 @c block, to get page layout right.
822 @c Setting indent in \paper block makes not much sense, but it works.
824 @c Bit verbose and vague, use examples?
825 The most basic settings influencing the spacing are @code{indent} and
826 @code{line-width}. They are set in the @code{\layout} block. They
827 control the indentation of the first line of music, and the lengths of
830 If @code{ragged-right} is set to true in the @code{\layout} block, then
831 systems ends at their natural horizontal length, instead of being spread
832 horizontally to fill the whole line. This is useful for
833 short fragments, and for checking how tight the natural spacing is.
836 @cindex vertical spacing
838 The option @code{ragged-last} is similar to @code{ragged-right}, but
839 only affects the last line of the piece. No restrictions are put on
840 that line. The result is similar to formatting text paragraphs. In a
841 paragraph, the last line simply takes its natural horizontal length.
842 @c Note that for text there are several options for the last line.
843 @c While Knuth TeX uses natural length, lead typesetters use the same
844 @c stretch as the previous line. eTeX uses \lastlinefit to
845 @c interpolate between both these solutions.
865 @subsection Line breaking
868 @cindex breaking lines
870 Line breaks are normally computed automatically. They are chosen so
871 that lines look neither cramped nor loose, and that consecutive lines
872 have similar density.
874 Occasionally you might want to override the automatic breaks; you can
875 do this by specifying @code{\break}. This will force a line break at
876 this point. Line breaks can only occur at places where there are bar
877 lines. If you want to have a line break where there is no bar line,
878 you can force an invisible bar line by entering @code{\bar
879 ""}. Similarly, @code{\noBreak} forbids a line break at a
883 @cindex regular line breaks
884 @cindex four bar music.
886 For line breaks at regular intervals use @code{\break} separated by
887 skips and repeated with @code{\repeat}:
889 << \repeat unfold 7 @{
890 s1 \noBreak s1 \noBreak
891 s1 \noBreak s1 \break @}
892 @emph{the real music}
897 This makes the following 28 measures (assuming 4/4 time) be broken every
898 4 measures, and only there.
902 @code{\break}, and @code{\noBreak}.
908 Internals: @internalsref{BreakEvent}.
910 A linebreaking configuration can now be saved as a @code{.ly} file
911 automatically. This allows vertical alignments to be stretched to
912 fit pages in a second formatting run. This is fairly new and
913 complicated; see @inputfileref{input/regression/,page-layout-twopass.ly}
918 Line breaks can only occur if there is a ``proper'' bar line. A note
919 which is hanging over a bar line is not proper, such as
921 @lilypond[quote,ragged-right,relative=2,fragment,verbatim]
922 c4 c2 c2 \break % this does nothing
923 c2 c4 | % a break here would work
924 c4 c2 c4 ~ \break % as does this break
930 @subsection Page breaking
932 The default page breaking may be overriden by inserting
933 @code{\pageBreak} or @code{\noPageBreak} commands. These commands are
934 analogous to @code{\break} and @code{\noBreak}. They should be
935 inserted at a bar line. These commands force and forbid a page-break
936 from happening. Of course, the @code{\pageBreak} command also forces
939 Page breaks are computed by the @code{page-breaking} function in the
942 To force a new page for a new piece (in a collection of pieces or a
943 piece in several movements), use @code{breakbefore} in the header.
956 @funindex \noPageBreak
962 The @code{breakbefore=##t} header requires that there is a @code{piece}
963 header as well. It may be used as a normal header, or left blank
964 (@code{=""}) as in the example above, but it must be present.
967 @node Displaying spacing
968 @section Displaying spacing
970 @funindex annotate-spacing
971 @cindex Spacing, display of properties
973 To graphically display the dimensions of vertical properties
974 that may be altered for page formatting, use
977 \paper { annotate-spacing = ##t }
982 @c FIXME: really bad vagueness due to bug in annotate-spacing. -gp
983 Some unit dimensions are measured in staff spaces, while others
984 are measured in millimeters.
986 (@var{a},@var{b}) are intervals, where @var{a} is the lower edge and
987 @var{b} the upper edge of the interval.