How to plot title with a subtitle on a newline

Is there a way to plot a title on two lines instead of one? I.e. Something like a title and a subtitle. I have some long titles that I would like to break onto a newline, but using \n doesn’t seem to work:

gmt basemap -R0/1/0/1 -JX1 -Baf+t"Title\nSubtitle" -png map

map

This comes up from time to time; perhaps time to make it a feature request, @weiji14? It should not be too hard to implement: Count the \n, then break into line with last line going where current single-line titles goes and work upwards with some sense of line-spacing derived from font size.

Ah, would have thought this was fairly common. I’ve opened up a feature request at https://github.com/GenericMappingTools/gmt/issues/4557.

In the meantime, I’ll try making a hacky workaround using legend :see_no_evil:

I did it using text (e.g.):

echo $titlIND1 | gmt text -F+cTR -D0c/0.6c -N

I’m trying to do something similar to this where I have a title and I want a subtitle that is of the data of an earthquake. I tried the gmt text approach (using classic mode)
echo $ename | gmt pstext -J$proj -R$LONMIN/$LONMAX/$LATMIN/$LATMAX \ -F+f32p,Times-Roman+cCT -D0c/0.6c -N -K -O >> $psfile

This is an iterative loop for multiple events so I need some dynamic variables. The problem I’m having is this is plotting the text just outside the framed boarder and I want the text just inside the actual map. I can migrate this text inside the map if I have to with Illustrator but there are a ton of events to do so any way I can reduce the amount of post processing fixes, the better. Here is an example of what it looks like from this line of code. As you can see, it interferes with the map tic marks. Any advice on how to improve this is appreciated.

Hi @jpschmidt is the map size always the same? Tweaking -D didn’t do the trick for you?

1 Like

Thanks for pointing that out. I didn’t think to play with the -D flag. I set the -D flag to -D0c/-1.0c for negative displacement and that worked great.

Did this finally get settled? I read the github feature request and tried some of the ideas thrown around, there, but without success, using the latest GMT version.

I just want to be able to send a newline to (classic) pstext (not looking to do a plot title). Something like this:

echo "1 3 top line\nbottom line" | gmt pstext -J -R -F+f12,1+jBC -O -K >> $psfile

How is adding a newline to pstext actually accomplished?

Thanks!

Multiline text has always been done via -M. Vi have no handling of newlines in single text strings.

So this can’t be done? The -M requires multi segment files. I just need to send a newline within an echo command.

You can send multiple lines with a single printf command (which may have newlines) instead of echo.

Ha! I’m showing my age. I learned bash back in the late 90’s, before printf existed! Thanks, Paul!

Sheesh. I must be dense. I’m still not getting this. Trying:

printf "%f %f %s\n%s\n" 2.5 3.5 first second | gmt pstext -JX11i/8.5i -R0/11/0/8.5 -F+f12,1+jML -X-1i -Y-1i > $OUTMAP
pstext [WARNING]: Mismatch between actual (1) and expected (2) fields near line 2 in file <Standard Input>

Resulting in a page with only the word “first” on it.

Think you are forgetting about the -M option.

I tried it with and without -M. Couldn’t succeed… my variations on a theme:

printf "%f %f %s\n%s\n" 2.5 3.5 first second | gmt pstext -JX11i/8.5i -R0/11/0/8.5 -M -F+f12,1+jML -X-1i -Y-1i > $OUTMAP
pstext [ERROR]: Text record line 0 not preceded by paragraph information, skipped)
pstext [ERROR]: Text record line 0 not preceded by paragraph information, skipped)

printf "> %f %f %s\n%s\n" 2.5 3.5 first second | gmt pstext -JX11i/8.5i -R0/11/0/8.5 -M -F+f12,1+jML -X-1i -Y-1i > $OUTMAP
pstext [WARNING]: Horizontal text justification not set, defaults to L(eft)
pstext [WARNING]: Length <unit> t not supported - revert to default unit [cm]
pstext [WARNING]: firs not a valid number and may not be decoded properly.
pstext [WARNING]:  not a valid number and may not be decoded properly.
pstext [ERROR]: Record 0 had incomplete paragraph information, skipped)
pstext [ERROR]: Text record line 0 not preceded by paragraph information, skipped)

Please illustrate how this works. Not clear enough…

Just carefully read the pstext +M documentation, e.g.

Paragraph mode. Files must be multiple segment files. Segments are separated by a special record whose first character must be *flag* [Default is **>** ]

So probably

printf “> %f %f %s\n%s\n” 2.5 3.5 first second

Sorry, Paul. Prefacing with “>” was exactly what I tried in my second variation on a theme, above. Received four warning messages and two error messages. Could you try it yourself and tell me whether it works for you? Just cut and paste:

printf "> %f %f %s\n%s\n" 2.5 3.5 first second | gmt pstext -JX11i/8.5i -R0/11/0/8.5 -M -F+f12,1+jML -X-1i -Y-1i > t.ps

I’m aiming to get the words “first” and “second” to be left justified with the word “first” positioned above the word “second.” This is all just to learn how this can be done.

Sorry, did not read carefully. Per the -M docs and the example further down, you would need something like this:

printf “> %f %f 13p 3i l\n%s\n\n%s\n” 2.5 3.5 first second

The extra blank line is because you are not actually typesetting text but want each item to be a separate line but don’t want to call pstext twice.

THe 13p 3i and l can change. It is the line spacing and paragraph width and justification.

1 Like

Hi GMT forum,

I’m trying to write a multiline title for my legend but without success. Could anyone help?

Below is my initial approach. I’d like the “from average [@.C]” to be written below “temperature deviation” and centred. I’ve tried /n,/r,@^ within the “…”, but they didn’t work.

gmt psscale -C${temperature_cpt} -R -J -DjRB+w6c/0.5ch+e+o0/-1 -Ba750f187:“Temperature deviation from average [@.C]”: -O >> $psfile

I’m quite new with the use of GMT, can this be done? Thank you in advance!
Screen Shot 2022-08-24 at 1.55.10 pm|349x247 .

Sorry nobody responded on this. There is no breaking a title into two lines, but there is a subtitle option for plot titles (see +s and +t). But your colon syntax is GMT 4 so that is not good to mix with modern syntax.