📄 title_options.hlp
字号:
{pstd}
the title will consist of two lines, the first line being "One" and the
second, "Two". In
{phang2}
. {cmd:graph} ...{cmd:, title("One")} ... {cmd:title("Two", prefix)} ...
{pstd}
the first line will be "Two" and the second line "One".
{pstd}
Repeatedly specifying title options may seem silly, but it is easier to do
than you might expect. Consider the command
{phang2}
{cmd}. twoway
(sc y1 x1, title("x1 vs. y1"))
(sc y2 x2, title("x2 vs. y2")){txt}
{pstd}
{cmd:title()} is in fact an option of {cmd:twoway}, not {cmd:scatter}, and
graphs have only one {cmd:title()} (although it might consist of multiple
lines). Thus the above is probably not what the user intended. Had the user
typed
{phang2}
{cmd}. twoway
(sc y1 x1)
(sc y2 x2),
title("x1 vs. y1") title("x2 vs. y2"){txt}
{pstd}
he would have seen his mistake. It is, however, okay to put {cmd:title()}
options inside the {cmd:scatter}s; {cmd:twoway} knows to pull them out.
Nevertheless, only the rightmost one will be honored (because neither
{cmd:prefix} nor {cmd:suffix} were specified), and thus the title of this
graph will be "x2 vs. y2".
{pstd}
Multiple title options arise usefully when you are using a command that
draws graphs that itself is written in terms of {cmd:graph}. For instance,
the command {cmd:sts} {cmd:graph} (see {helpb sts}) will graph
the Kaplan-Meier survivor function. When you type
{cmd:. sts graph}
{pstd}
with the appropriate data in memory, a graph will appear, and that graph will
have a {cmd:title()}. Yet, if you type
{phang2}
{cmd:. sts graph, title("Survivor function for treatment 1")}
{pstd}
your title will override {cmd:sts} {cmd:graph}'s default. Inside the code
of {cmd:sts} {cmd:graph}, both {cmd:title()} options appear on the {cmd:graph}
command. First, appears the default and second appears the one that you
specified. This programming detail is worth understanding because, as an
implication, if you type
{phang2}
{cmd:. sts graph, title("for treatment 1", suffix)}
{pstd}
your title will be suffixed to the default. Most commands work this way,
so if you use some command and it produces a title you do not like,
specify {cmd:title()} (or {cmd:subtitle()}, ...) to override it, or
specify {cmd:title(}...{cmd:,} {cmd:suffix)} (or
{cmd:subtitle(}...{cmd:,} {cmd:suffix)}, ...) to add to it.
{hline}
{pmore}
{it:Technical note:}
Title options before the rightmost one are not completely ignored. Their
options are merged and honored, so if a title is moved or the color changed
early on, the title will continue to be moved or the color changed. You can
always specify the options to change it back.
{p_end}
{hline}
{marker remarks3}{...}
{title:Positioning of titles}
{pstd}
Where titles appear is determined by the scheme that you choose; see
{help schemes}. Options {cmd:position(}{it:clockposstyle}{cmd:)} and
{cmd:ring(}{it:ringpos}{cmd:)} override that location and let you place the
title where you want it.
{pstd}
{cmd:position()} specifies a direction {it:(sic)} according to the hours of a
12-hour clock and {cmd:ring()} specifies how far from the plot region the
title is to appear.
Interpretation of clock {cmd:position()}
{cmd:ring(}{it:k}{cmd:)}, {it:k}>0, and {cmd:ring(0)}
{c TLC}{hline 39}{c TRC}
{c |} 11 12 1 {c |}
{c |} {c |}
{c |} {c TLC}{hline 23}{c TRC} {c |}
{c |}10 {c |}10 or 11 12 1 or 2 {c |} 2 {c |}
{c |} {c |} {c |} {c |}
{c |} {c |} {c |} {c |}
{c |} 9 {c |} 9 0 3 {c |} 3 {c |}
{c |} {c |} {c |} {c |}
{c |} {c |} {c |} {c |}
{c |} 8 {c |} 7 or 8 6 4 or 5 {c |} 4 {c |}
{c |} {c BLC}{hline 23}{c BRC} {c |}
{c |} {c |}
{c |} 7 6 5 {c |}
{c BLC}{hline 39}{c BRC}
Interpretation of {cmd:ring()}
{hline 25}{c TT}{hline 25}
plot region 0 {c |} {cmd:ring(0)} = plot region
{c -(}{cmd:t}|{cmd:b}|{cmd:l}|{cmd:r}{c )-}{cmd:1title()} 1 {c |}
{c -(}{cmd:t}|{cmd:b}|{cmd:l}|{cmd:r}{c )-}{cmd:2title()} 2 {c |} {cmd:ring(}{it:k}{cmd:)}, {it:k}>0, is outside
{cmd:legend()} 3 {c |} the plot region
{cmd:note()} 4 {c |}
{cmd:caption()} 5 {c |} the larger the {cmd:ring()}
{cmd:subtitle()} 6 {c |} value, the farther
{cmd:title()} 7 {c |} away
{hline 25}{c BT}{hline 25}
{pstd}
{cmd:position()} has two interpretations, one for {cmd:ring(0)} and
another for {cmd:ring(}{it:k}{cmd:)}, {it:k}>0. {cmd:ring(0)} is for the
special case when you are placing a title directly on top of the plot.
Put that case aside; titles usually appear outside the plot region.
{pstd}
A title directly above the plot region is at {cmd:position(12)},
a title to the right at {cmd:position(3)}, and so on. If you put
your title at {cmd:position(1)}, it will end up above and to the
right of the plot region.
{pstd}
Now consider two titles{hline 2}say {cmd:title()} and
{cmd:subtitle()}{hline 2}both
located at {cmd:position(12)}. Which is to appear first? That is
determined by their respective {cmd:ring()} values. {cmd:ring()}
specifies ordinally how far a title is from the plot region.
The title with the larger {cmd:ring()} value is placed
farther out. {cmd:ring()} values may be integer or noninteger.
{pstd}
For instance, {cmd:legend()} (see {it:{help legend_option}})
is closer to the plot region than
{cmd:caption()} because, by default, {cmd:legend()} has a {cmd:ring()}
value of 4 and {cmd:caption()} a {cmd:ring()} value of 5. Because both
appear at {cmd:position(7)}, both appear below the plot region and
because 4<5, the {cmd:legend()} appears above the {cmd:caption()}.
These defaults assume you are using the default scheme.
{pstd}
If you wanted to put your legend below the caption, you could specify
{phang3}
{cmd:. graph} ...{cmd:, legend(}... {cmd:ring(5.5)) caption("My caption")}
{pstd}
or
{phang3}
{cmd:. graph} ...{cmd:, legend(}...{cmd:) caption("My caption", ring(3.5))}
{pstd}
The plot region itself is defined as {cmd:ring(0)}, and if you specified
that, the title would appear inside the plot region, right on top of what
is plotted! You can specify where inside the plot region you want the
title using {cmd:position()}, and the title will put itself on the
corresponding edge of the plot region. In {cmd:ring(0)}, the clock
positions 1 and 2, 4 and 5, 7 and 8, and 10 and 11 are treated as being
the same. In addition, {cmd:position(0)} designates the center of the
plot region.
{pstd}
Within the plot region{hline 2}within {cmd:ring(0)}{hline 2}given a
{cmd:position()}, you can further shift the title up or down or left or
right by specifying the title's {cmd:margin()} {it:textbox_option}. For
instance, you might specify
{phang2}
{cmd:. graph} ...{cmd:, caption(}...{cmd:, ring(0) pos(7))} ...
{pstd}
and then discover that the caption needed to be moved up and right
a little, and so change the {cmd:caption()} option to read
{phang2}
{cmd:. graph} ...{cmd:, caption(}...{cmd:, ring(0) pos(7) margin(medium))} ...
{pstd}
See {it:{help textbox_options}} and
{it:{help marginstyle}} for more information on the {cmd:margin()}
option.
{marker remarks4}{...}
{title:Alignment of titles}
{pstd}
How should the text be placed in the textbox: left-justified, centered, or
right-justified? The defaults that have been set vary according to
title type:
title type default justification
{hline 45}
{cmd:title()} centered
{cmd:subtitle()} centered
{c -(}{cmd:t}|{cmd:b}|{cmd:l}|{cmd:r}{c )-}{c -(}{cmd:1}|{cmd:2}{c )-}{cmd:title()} centered
{cmd:note()} left-justified
{cmd:caption()} left-justified
{hline 45}
{pstd}
Actually, how a title is justified is, by default, determined by the scheme,
and in the above, we assume that you are using a default scheme.
{pstd}
You can change that justification using the
{it:textbox_option}
{cmd:justification(}{cmd:left}|{cmd:center}|{cmd:right)}.
For instance,
{phang2}
{cmd:. graph} ...{cmd:, title("My title", justification(left))} ...
{pstd}
See {it:{help textbox_options}}.
{marker remarks5}{...}
{title:Spanning}
{pstd}
Option {cmd:span} specifies that the title is to be placed in an area spanning
the entire width (or height) of the graph rather than an area spanning the
plot region. That is,
{c TLC}{hline 39}{c TRC} {c -}
{c |} {c |} {c |}
{c |}<--------------- span ---------------->{c |} {c |}
{c |} {c |} {c |}
{c |} |<------ default ------>| {c |} {c |}
{c |} {c TLC}{hline 23}{c TRC} {c |} {c -} {c |}
{c |} {c |} {c |} {c |} {c |} {c |}
{c |} {c |} {c |} {c |} {c |} span
{c |} {c |} {it:plot} {c |} {c |} default {c |}
{c |} {c |} {it:region} {c |} {c |} {c |} {c |}
{c |} {c |} {c |} {c |} {c |} {c |}
{c |} {c |} {c |} {c |} {c |} {c |}
{c |} {c BLC}{hline 23}{c BRC} {c |} {c -} {c |}
{c |} {c |} {c |}
{c BLC}{hline 39}{c BRC} {c -}
{pstd}
For instance, the {cmd:title()} is usually centered at the top of the graph.
Is it to be centered above the plot region (the default) or between the
borders of the entire available area ({cmd:title(}...{cmd:,} {cmd:span)}
specified)? The {cmd:note()} is usually presented left-justified below
the plot region. Is it left-justified to align with the border
of the plot region (the default), or left-justified to the entire
available area ({cmd:note(}...{cmd:,} {cmd:span)} specified)?
{pstd}
Do not confuse {cmd:span} with the {it:textbox} option
{cmd:justification(}{cmd:left}|{cmd:center}|{cmd:right)} which places the text
left-justified, centered, or right-justified in whatever area is being
spanned; see {hi:Alignment of titles} above.
{marker remarks6}{...}
{title:Using the textbox options box and bexpand}
{pstd}
The {it:textbox_options} {cmd:box} and {cmd:bexpand}{hline 2}see
{it:{help textbox_options}}{hline 2}can be put to effective use with titles.
Look at three graphs:
{phang2}
{cmd:. scatter mpg weight, title("Mileage and weight")}
{p_end}
{it:({stata `"gr_example auto: scatter mpg weight, title("Mileage and weight")"':click to run})}
{* graph ttlops1}{...}
{phang2}
{cmd:. scatter mpg weight, title("Mileage and weight", box)}
{p_end}
{it:({stata `"gr_example auto: scatter mpg weight, title("Mileage and weight", box)"':click to run})}
{* graph ttlops2}{...}
{phang2}
{cmd:. scatter mpg weight, title("Mileage and weight", box bexpand)}
{p_end}
{it:({stata `"gr_example auto: scatter mpg weight, title("Mileage and weight", box bexpand)"':click to run})}
{* graph ttlops3}{...}
{pstd}
We want to direct your attention to the treatment of the title, which will
be
Mileage and weight
{c TLC}{hline 20}{c TRC}
{c |} Mileage and weight {c |}
{c BLC}{hline 20}{c BRC}
{c TLC}{hline 48}{c TRC}
{c |} Mileage and weight {c |}
{c BLC}{hline 48}{c BRC}
{pstd}
Without options, the title appeared as is.
{pstd}
The textbox option {cmd:box} drew a box around the title.
{pstd}
The textbox options {cmd:bexpand} expanded the box to line up with the
plot region and drew a box around the expanded title.
{pstd}
In both the second and third examples, in the graphs you will also note
that the background of the textbox was shaded. That is because most schemes
set the textbox option {cmd:bfcolor()}, but {cmd:bfcolor()} only becomes
effective when the textbox is {cmd:box}ed.
{title:Also see}
{psee}
Manual: {bf:[G] {it:title_options}}
{psee}
Online:
{it:{help legend_option}};
{it:{help textbox_options}},
{help schemes}
{p_end}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -