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 @findex first-page-number
113 @item first-page-number
114 The value of the page number of the first page. Default is@tie{}1.
116 @findex 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 @findex print-page-number
122 @item print-page-number
123 If set to false, page numbers will not be printed.
127 The width of the page.
131 The height of the page.
135 Margin between header and top of the page.
137 @findex bottom-margin
139 Margin between footer and bottom of the page.
143 Margin between the left side of the page and the beginning of the music.
147 The length of the systems.
149 @findex head-separation
150 @item head-separation
151 Distance between the top-most music system and the page header.
153 @findex foot-separation
154 @item foot-separation
155 Distance between the bottom-most music system and the page footer.
157 @findex 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 @findex 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 @findex 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
180 This variable, if set, specifies into how many lines a score should be
183 @findex 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 @findex 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 @findex 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 @findex after-title-space
210 @item after-title-space
211 Amount of space between the title and the first system.
213 @findex after-title-space
214 @item before-title-space
215 Amount of space between the last system of the previous piece and the
218 @findex 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 @findex 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 @findex 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
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
429 Vertical spacing is controlled by three things: the amount of
430 space available (i.e. paper size and margins), the amount of
431 space between systems, and the amount of space between
432 staves inside a system.
435 * Vertical spacing inside a system::
436 * Vertical spacing of piano staves::
437 * Vertical spacing between systems::
438 * Controlling spacing of individual systems::
442 @node Vertical spacing inside a system
443 @subsection Vertical spacing inside a system
445 @cindex distance between staves
446 @cindex staff distance
447 @cindex space between staves
448 @cindex space inside systems
450 The height of each system is determined automatically. To prevent
451 staves from bumping into each other, some minimum distances are set.
452 By changing these, you can put staves closer together. This
453 reduces the amount of space each system requires, and may result
454 in having more systems per page.
456 Normally staves are stacked vertically. To make staves maintain a
457 distance, their vertical size is padded. This is done with the
458 property @code{minimum-Y-extent}. When applied to a
459 @internalsref{VerticalAxisGroup}, it controls the size of a horizontal
460 line, such as a staff or a line of lyrics. @code{minimum-Y-extent}
461 takes a pair of numbers, so
462 if you want to make it smaller than its default @code{#'(-4 . 4)}
466 \override Staff.VerticalAxisGroup #'minimum-Y-extent = #'(-3 . 3)
470 This sets the vertical size of the current staff to 3 staff spaces on
471 either side of the center staff line. The value @code{(-3 . 3)} is
472 interpreted as an interval, where the center line is the 0, so the
473 first number is generally negative. The numbers need not match;
474 for example, the staff can be made larger at the bottom by setting
475 it to @code{(-6 . 4)}.
480 Internals: Vertical alignment of staves is handled by the
481 @internalsref{VerticalAlignment} object. The context parameters
482 specifying the vertical extent are described in connection with
483 the @internalsref{Axis_group_engraver}.
485 Example files: @inputfileref{input/regression/,page-spacing.ly},
486 @inputfileref{input/regression/,alignment-vertical-spacing.ly}.
489 @node Vertical spacing of piano staves
490 @subsection Vertical spacing of piano staves
492 The distance between staves of a @internalsref{PianoStaff} cannot be
493 computed during formatting. Rather, to make cross-staff beaming work
494 correctly, that distance has to be fixed beforehand.
496 The distance of staves in a @code{PianoStaff} is set with the
497 @code{forced-distance} property of the
498 @internalsref{VerticalAlignment} object, created in
499 @internalsref{PianoStaff}.
501 It can be adjusted as follows
503 \new PianoStaff \with @{
504 \override VerticalAlignment #'forced-distance = #7
511 This would bring the staves together at a distance of 7 staff spaces,
512 measured from the center line of each staff.
514 The difference is demonstrated in the following example,
515 @lilypond[quote,verbatim]
517 \new PianoStaff \with {
518 \override VerticalAlignment #'forced-distance = #7
533 Example files: @inputfileref{input/regression/,alignment-vertical-spacing.ly}.
536 @node Vertical spacing between systems
537 @subsection Vertical spacing between systems
539 Space between systems are controlled by four @code{\paper} variables,
543 between-system-space = 1.5\cm
544 between-system-padding = #1
546 ragged-last-bottom=##f
551 @node Controlling spacing of individual systems
552 @subsection Controlling spacing of individual systems
554 It is also possible to change the distance between for each system
555 individually. This is done by including the command
559 #"Score.NonMusicalPaperColumn"
560 #'line-break-system-details
561 #'((fixed-alignment-extra-space . 15))
565 at the line break before the system to be changed. The distance
566 @code{15} is distributed over all staves that have a fixed distance
567 alignment. For example,
569 @lilypond[ragged-right, fragment, relative=2, staffsize=13]
575 #"Score.NonMusicalPaperColumn"
576 #'line-break-system-details
577 #'((fixed-alignment-extra-space . 15))
585 The distance for @code{fixed-alignment-extra-space} may also be
590 @node Horizontal spacing
591 @section Horizontal Spacing
599 @node Horizontal Intro
600 @subsection Horizontal Intro
602 The spacing engine translates differences in durations into stretchable
603 distances (``springs'') of differring lengths. Longer durations get
604 more space, shorter durations get less. The shortest durations get a
605 fixed amount of space (which is controlled by
606 @code{shortest-duration-space} in the @internalsref{SpacingSpanner}
607 object). The longer the duration, the more space it gets: doubling a
608 duration adds a fixed amount (this amount is controlled by
609 @code{spacing-increment}) of space to the note.
611 For example, the following piece contains lots of half, quarter, and
612 8th notes; the eighth note is followed by 1 note head width (NHW).
613 The quarter note is followed by 2 NHW, the half by 3 NHW, etc.
615 @lilypond[quote,fragment,verbatim,relative=1]
616 c2 c4. c8 c4. c8 c4. c8 c8
620 Normally, @code{spacing-increment} is set to 1.2 staff space, which is
621 approximately the width of a note head, and
622 @code{shortest-duration-space} is set to 2.0, meaning that the
623 shortest note gets 2.4 staff space (2.0 times the
624 @code{spacing-increment}) of horizontal space. This space is counted
625 from the left edge of the symbol, so the shortest notes are generally
626 followed by one NHW of space.
628 If one would follow the above procedure exactly, then adding a single
629 32nd note to a score that uses 8th and 16th notes, would widen up the
630 entire score a lot. The shortest note is no longer a 16th, but a 32nd,
631 thus adding 1 NHW to every note. To prevent this, the shortest
632 duration for spacing is not the shortest note in the score, but rather
633 the one which occurs most frequently.
636 The most common shortest duration is determined as follows: in every
637 measure, the shortest duration is determined. The most common shortest
638 duration is taken as the basis for the spacing, with the stipulation
639 that this shortest duration should always be equal to or shorter than
640 an 8th note. The shortest duration is printed when you run
641 @code{lilypond} with the @code{--verbose} option.
643 These durations may also be customized. If you set the
644 @code{common-shortest-duration} in @internalsref{SpacingSpanner}, then
645 this sets the base duration for spacing. The maximum duration for this
646 base (normally an 8th), is set through @code{base-shortest-duration}.
648 @findex common-shortest-duration
649 @findex base-shortest-duration
650 @findex stem-spacing-correction
653 Notes that are even shorter than the common shortest note are
654 followed by a space that is proportional to their duration relative to
655 the common shortest note. So if we were to add only a few 16th notes
656 to the example above, they would be followed by half a NHW:
658 @lilypond[quote,fragment,verbatim,relative=2]
659 c2 c4. c8 c4. c16[ c] c4. c8 c8 c8 c4 c4 c4
663 In the introduction (see @ref{Engraving}), it was explained that stem
664 directions influence spacing. This is controlled with the
665 @code{stem-spacing-correction} property in the
666 @internalsref{NoteSpacing}, object. These are generated for every
667 @internalsref{Voice} context. The @code{StaffSpacing} object
668 (generated in @internalsref{Staff} context) contains the same property
669 for controlling the stem/bar line spacing. The following example shows
670 these corrections, once with default settings, and once with
671 exaggerated corrections:
673 @lilypond[quote,ragged-right]
677 \override Staff.NoteSpacing #'stem-spacing-correction = #1.5
678 \override Staff.StaffSpacing #'stem-spacing-correction = #1.5
684 Proportional notation is supported; see @ref{Proportional notation}.
686 By default, spacing in tuplets depends on various non-duration
687 factors (such as accidentals, clef changes, etc). To disregard
688 such symbols and force uniform equal-duration spacing, use
689 @code{Score.SpacingSpanner #'uniform-stretching}. This
690 property can only be changed at the beginning of a score,
692 @lilypond[quote,ragged-right,relative=2,fragment,verbatim]
694 \override SpacingSpanner #'uniform-stretching = ##t
712 When @code{strict-note-spacing} is set, notes are spaced without
713 regard for clefs, bar lines, and grace notes,
715 @lilypond[quote,ragged-right,relative=2,fragment,verbatim]
716 \override Score.SpacingSpanner #'strict-note-spacing = ##t
717 \new Staff { c8[ c \clef alto c \grace { c16[ c] } c8 c c] c32[ c32] }
723 Internals: @internalsref{SpacingSpanner}, @internalsref{NoteSpacing},
724 @internalsref{StaffSpacing}, @internalsref{SeparationItem}, and
725 @internalsref{SeparatingGroupSpanner}.
729 Spacing is determined on a score wide basis. If you have a score that
730 changes its character (measured in durations) halfway during the
731 score, the part containing the longer durations will be spaced too
734 There is no convenient mechanism to manually override spacing. The
735 following work-around may be used to insert extra space into a score.
737 \once \override Score.SeparationItem #'padding = #1
740 No work-around exists for decreasing the amount of space.
744 @subsection Line length
747 @cindex breaking pages
754 @c Although line-width can be set in \layout, it should be set in paper
755 @c block, to get page layout right.
756 @c Setting indent in \paper block makes not much sense, but it works.
758 @c Bit verbose and vague, use examples?
759 The most basic settings influencing the spacing are @code{indent} and
760 @code{line-width}. They are set in the @code{\layout} block. They
761 control the indentation of the first line of music, and the lengths of
764 If @code{ragged-right} is set to true in the @code{\layout} block, then
765 systems ends at their natural horizontal length, instead of being spread
766 horizontally to fill the whole line. This is useful for
767 short fragments, and for checking how tight the natural spacing is.
770 @cindex vertical spacing
772 The option @code{ragged-last} is similar to @code{ragged-right}, but
773 only affects the last line of the piece. No restrictions are put on
774 that line. The result is similar to formatting text paragraphs. In a
775 paragraph, the last line simply takes its natural horizontal length.
776 @c Note that for text there are several options for the last line.
777 @c While Knuth TeX uses natural length, lead typesetters use the same
778 @c stretch as the previous line. eTeX uses \lastlinefit to
779 @c interpolate between both these solutions.
799 @subsection Line breaking
802 @cindex breaking lines
804 Line breaks are normally computed automatically. They are chosen so
805 that lines look neither cramped nor loose, and that consecutive lines
806 have similar density.
808 Occasionally you might want to override the automatic breaks; you can
809 do this by specifying @code{\break}. This will force a line break at
810 this point. Line breaks can only occur at places where there are bar
811 lines. If you want to have a line break where there is no bar line,
812 you can force an invisible bar line by entering @code{\bar
813 ""}. Similarly, @code{\noBreak} forbids a line break at a
817 @cindex regular line breaks
818 @cindex four bar music.
820 For line breaks at regular intervals use @code{\break} separated by
821 skips and repeated with @code{\repeat}:
823 << \repeat unfold 7 @{
824 s1 \noBreak s1 \noBreak
825 s1 \noBreak s1 \break @}
826 @emph{the real music}
831 This makes the following 28 measures (assuming 4/4 time) be broken every
832 4 measures, and only there.
836 @code{\break}, and @code{\noBreak}.
842 Internals: @internalsref{BreakEvent}.
844 A linebreaking configuration can now be saved as a @code{.ly} file
845 automatically. This allows vertical alignments to be stretched to
846 fit pages in a second formatting run. This is fairly new and
847 complicated; see @inputfileref{input/regression/,page-layout-twopass.ly}
852 Line breaks can only occur if there is a ``proper'' bar line. A note
853 which is hanging over a bar line is not proper, such as
855 @lilypond[quote,ragged-right,relative=2,fragment,verbatim]
856 c4 c2 c2 \break % this does nothing
857 c2 c4 | % a break here would work
858 c4 c2 c4 ~ \break % as does this break
864 @subsection Page breaking
866 The default page breaking may be overriden by inserting
867 @code{\pageBreak} or @code{\noPageBreak} commands. These commands are
868 analogous to @code{\break} and @code{\noBreak}. They should be
869 inserted at a bar line. These commands force and forbid a page-break
870 from happening. Of course, the @code{\pageBreak} command also forces
873 Page breaks are computed by the @code{page-breaking} function in the
876 To force a new page for a new piece (in a collection of pieces or a
877 piece in several movements), use @code{breakbefore} in the header.
896 The @code{breakbefore=##t} header requires that there is a @code{piece}
897 header as well. It may be used as a normal header, or left blank
898 (@code{=""}) as in the example above, but it must be present.
901 @node Displaying spacing
902 @section Displaying spacing
904 @findex annotate-spacing
905 @cindex Spacing, display of properties
907 To graphically display the dimensions of vertical properties
908 that may be altered for page formatting, use
911 \paper { annotate-spacing = ##t }
916 @c FIXME: really bad vagueness due to bug in annotate-spacing. -gp
917 Some unit dimensions are measured in staff spaces, while others
918 are measured in millimeters.
920 (@var{a},@var{b}) are intervals, where @var{a} is the lower edge and
921 @var{b} the upper edge of the interval.