Line Break in Expression()

Line break in expression()?

You can easily use line breaks in regular paste, but this is plotmath paste (actually a different function also with no 'sep' argument) and the (long) ?plotmath page specifically tells you it cannot be done. So what's the work-around? Using the plotmath function atop is one simple option:

expression(atop("Histogram of "*hat(mu), Bootstrap~samples*','~Allianz))

This will break at the comma and center the plotmath expressions. More complicated options are available.

This illustrates plotting to a graphics file. Ironically, the first effort gave me a display that did have your problem with the 'hat' (are those circumflexes?) being cut off and this shows how to increase the margins. The top margin is probably the third number so c(3,3,8,0) might suit you better:

 pdf("test.pdf") ;  par(mar=c(10,10,10,10))
hist(1:10,cex.main=2,cex.axis=1.2,cex.lab=1.2,
main=expression(atop("Histogram of "*hat(mu),
Bootstrap~samples * ',' ~Allianz)))
dev.off() # don't need to restore; this 'par' only applies to pdf()

Expression and new line in plot labels

You can introduce a line break inside an expression:

bquote(atop("first line",
"second line" ~ x ^ 2))

(I’m using bquote rather than expression here – both work in this case.)

Execute demo(plotmath) for more information and look at the documentation for atop.

boxplot apparently has some trouble interpreting expressions in its title. A simple fix is to plot the title separately:

boxplot(data, main = '')
title(bquote(atop("first line", "second line" ~ x ^ 2)))

Adding a newline in a substitute() expression

\n cannot be used in plotmath expressions. You could perhaps break the expression in two parts, and use annotate to add the expressions where you want them. Or, use atop. Check out this post ->
Line break in expression()?

SSRS expression: How to put a line break after a special character for an address that is in a table column

I didn't test it in VBA, but it functions in Regex101 and is something like this through Regex Replace:

EDIT on 02/04/2022: I managed to get a VBA editor, and put things more DRY and SOLID...

Public Sub TestReplaceThroughRegex()
Dim strOutput As String
strOutput = _
ReplaceThroughRegex( _
"5)Passenger Lifts - Insurance - The High St 5-16- due - 28 Jan 22, 5)Passenger Lifts - Insurance - 6 Lovedale Road Flats- due - 09 Sep 21, 5)Passenger Lifts - Insurance - Queens Court 1 - 31 BLOCK- due - 14 Jan 22" _
, "\d{1}\)" _
, "\r" _
)
Debug.Print (strOutput)
End Sub

Public Function ReplaceThroughRegex(ByVal strInput As String, ByVal pattern As String, ByVal replacement As String) As String
Static regEx As Object 'VBScript_RegExp_55.RegExp
'Static declaration means we don't have to create
'and compile the RegExp object every single time
'the function is called.

If strInput = "" Then
'This is the signal to dispose of oRE
Set regEx = Nothing
Exit Function 'with default value
End If

'Create the RegExp object if necessary
If regEx Is Nothing Then
Set regEx = CreateObject("VBScript.Regexp")
End If
With regEx
.Global = True
.Multiline = True
.IgnoreCase = False
.pattern = pattern
End With
ReplaceThroughRegex = regEx.Replace(strInput, replacement)
End Function

PS: I'm assuming that you will have only 1 digit before ).
If more than one is possible, change for "\d{1,2}\)" or "\d{1,3}\)", whatever suits your needs.

SSRS Expression - Line break/new line after coma in value

I am fairly confident that what you want is not possible without assuming that the values between the commas will always be the same length.

Your text is breaking in the 'middle' of a value because SSRS does not know that your commas should be treated as breaking characters, like it would a space.

As a result, your options are limited and depend on what the purpose of this textbox is. If you just want to display the data, then you can worry less about how the break is defined but if you need to use this data elsewhere you do need to worry.

If you need to use the data elsewhere via copy and paste and you absolutely can't have the spaces you're mostly out of luck. If you don't have to copy the data anywhere you have two options you can simply add spaces after your commas to get the breaks you want in the report:

Option 1 - Visible Space Character

Use replace to swap all comma characters with a comma and a space which will show up on the report. Whilst this may not be aesthetically desirable, at least it is obvious what is happening in the report, unlike option 2...

=replace(Fields!YourCol.Value, ",", ", ")

Option 2 - Non-Visible Space Character

Use replace again, but swap the comma with a comma and a Zero-Width Space character. Whilst in the report design this will be apparent, anyone trying to copy the data may get issues as there are characters present that cannot be seen. You can see this by selecting the text he​re. As you hold shift and move left and right using the arrow keys, you will notice that you need an extra press to get between he and re.

The unicode character number you need for this is 8203, which you can use with the ChrW ssrs function:

=replace(Fields!YourCol.Value, ",", "," & chrw(8203))

Multiple line breaks in expression

A workaround is to use textstyle to draw in normal size:

plot(1,1,main=expression(
atop(textstyle("a"),
atop(textstyle("b"),
textstyle("c")
)
)
))

A maybe clearer solution is to use mtext several times, once for each line:

plot(1,1)
mtext(expression(bold("Fig. 3. Total yearly diffuse attenuation coefficient")), line=3)
mtext(expression(bold("at 490 nm (K"[d]*") and chlorophyll concentration")), line=1.9)
mtext(expression(bold("at 3 coral reef sites between 2003 and 2012")), line=1)

Note that in the second line I used line=1.9 to correct a little bit the interspacing because of the subscript:

Sample Image



Related Topics



Leave a reply



Submit