Vertical text alignment in Crystal Reports? - crystal-reports

In the Crystal Reports editor that comes with Visual Studio (2008) is it possible to align text to the center of a text box rather than to the top?
I can't find the option anywhere and a Google search is not encouraging but I just can't bring myself to believe that they would not include such an obvious feature.

There is no vertical alignment for crystal reports that I could find. A potential work-around is programming line breaks.

I can't find an option to vertically align text within a label, but you can vertically align labels within a section. Use the horizontal guidelines on the left margin to adjust the alignment. You may need to right-click the guideline and un-check "Snap to Grid" to get more precise positioning.

You can achieve this with strings, as you will see a paragraph tab instead of a number tab when you enter the FORMAT FIELD menu. To make your number a string you should format it as a formula field thusly:
chr(13) + chr(10) + totext(mynumber,0)
Then in the FORMAT FIELD menu select - Line spacing: multiple of: 0.2
You may need to experiment with the 0.2 value until you find your number (i.e. string prefixed with a carriage return) nicely centered in the middle of your box.
Cheers,
Chilly

Vertical alignment with programming line breaks. Algorithm for the one cell:
Count the number of characters in data (iTextLen).
Find the number of text lines in cell (iLineNum). Calculated empirically.
Find the row length in characters (iLineLen). Calculated empirically.
Calculate count the number of halfbreaks by formula (iLineNum — 1) — (iTextLen / iLineLen).
#formula in crystal syntax:
Local NumberVar iLineNum:= 5;
Local NumberVar iLineLen:= 30;
Local NumberVar iTextLen:= Length({DataSource});
Local StringVar sRet:= '';
Local NumberVar i;
Local NumberVar iLinesNum:= Truncate(iLineNum - 1) - Truncate(iTextLen / iLineLen);
For i:= 1 to iLinesNum Do ( sRet:= sRet + chr(13) );
sRet
Add formula to the top and bottom of data. Text objects will look like this:{#formula}{DataSource}{#formula}
Font size of #formula must be halved of font size {DataSource}. For example, if the font size of {DataSource} equal to 20, the #formula should be equal to 10:
Algorithm works better with monospaced typeface, but with proportional typeface works in most cases.
Algorithm for multiple cells is differ only that iLineNum will be the maximum number of characters in data of all cells.

in crystal report 10 the label >> right click >> format Text >> Common >> text rotation . choose 90 degree the text will have a vertical alignment
same in a field or any object you add to the report
hope that i help you
note the answer (Format text > tab Paragraph, Horizontal alignment: Centered) is a wrong

Related

Tableau: how to align text in dual axis-ed column labels

I am having trouble with label's text alignment. I used workaround to have rows coloured based on a value of certain row (featured in e.g. this tutorial); for example, if the Status is "Cancelled", it colours entire row red, otherwise it is green.
I created AGG(MAX(1)) columns for bar (with fixed range 0 to 1) and AGG(MAX(0)) columns for text (with fixed range 0 to 0), then paired them through dual axis.
However, I found out the text label is automatically aligned to the centre. I looked into text label options and set my alignment to the left (in both Edit Label window and Alignment setting) but it had no effect whatsoever. I changed Format... settings for column but once again, it had no effect.
I even tried changing fixed range on AGG(MAX(0)) columns or changing the zero in MAX(0) to some other number but this only moved centre-aligned text so it was of no use.
Here is a picture to illustrate my point:
I found out what was the issue and also arrived at better way to do it than the one I described in my question.
Here's the tutorial (using Tableau 2021.4):
Create a column MAX(-1). Right-click the column, go to Edit Axis..., set Range to fixed (start at -1, end at 0), delete the Title, and disable all Tick Marks (by setting them to 'None').
In Marks panel, set the Mark to 'Gantt Bar'.
Drop your condition for coloring (e.g. calculated field) on Color in Marks panel.
Create a calculated field MAX(1) and drop it on Size in Marks panel. This will fill out entire column width with a color bar. If needed, increase the bar width by moving the slider under Size to the right.
Drop the text value on Label in Marks panel. Now you should see text labels. If not, increase cell's height (Format > Cell Size > Taller or Ctrl+Up).
If you want a header (just like shown in my picture), create a column MAX(0), set its Range to fixed (start at 0, end at 0), disable all Tick Marks and change the Title.
Right-click the MAX(0) and tick 'Dual Axis'.
In case you'll encounter some challenges when formatting the end result, check formatting hierarchy (this tutorial may help).

Vertical Align Crystal Report Text Filed

I have a scenario in which my reports fields doesn't look like centered Vertically,
Below is the screen Short of the output.
As it can bee seen from output that data with a bigger font is clearly seen centered vertically, but the data pointed with lines is left-top justified, i want that to be left-centered.
For vertical alignment I did this .
and code behind formula is:
if {NewReport;1.TireLevel} = 1
then
crCenteredHorizontally
else
crLeftAligned
The Editor Screen.
Sadly, Crystal Reports doesn't support vertical alignment in the same way it supports horizontal.
It's possible to use labels on the vertical ruler and enforce Snap to Grid, but that might not work within a table. Or you can add line breaks, blank rows, or plain white objects to push things into position. But there's no easy way to enforce a vertical center.
In your particular case, I would actually make two seperate fields: One for large text and one for small text. Layer them on top of each other and reuse your current formula to alternate their suppression. This way you can move the smaller text vertically down without undoing the vertical alignment on the large text field.

Aligning BIRT charts regardless of the legend size

I have created a BIRT report with multiple charts.
All the charts include different data but for the same time span.
So i want to make the x axis of the charts align with each other so it is easy to read all the charts at once.
But the series names of these charts are different from each other.And some charts gets dynamic series names in which the length cannot be predicted.
Even though i align the charts with same width and height because of the series names the legend gets too lengthy and the alignment gets ruined.
According to the requirements given to me legend should be placed at the right side of the chart.
Is there a way to fix the size of the legend without truncating the series names.May be a way to wrap the series names so the size of the legend will be same for all the charts and the charts will be aligned nicely.
From your Eclipse designer:
Edit charts -> Format charts -> Legend -> Layout -> Wrapping width
Set a wrapping width value as expected, for example try 60.
You might also have to increase the bottom inset of legend entries to avoid overlapping:
Edit charts -> Format charts -> Legend -> Entries -> Bottom inset
From your Eclipse designer: set Format Chart->Legend->Entries->Ellipsis property to possible max length of your dynamic legends. and the problem will be solved.
As this property work as follows:
The default value is "1". Int attribute "Ellipsis" specifies the behavior of shortening the legend item's text with ellipsis if there is not enough space to display the whole text. Value 0 indicates that the feature is disabled, and the legend item will either be displayed with whole text or be dropped. A positive value n represents the minimal count of characters to be displayed before the ellipsis, which means the legend item will either be dropped or be displayed with at least n characters.
Hope this will solve your problem. It worked for me.

Create a Crystal Report cross-tab 'header' label

I'd like to create a 'header' label that 1) is centered over the cross-tab and 2) grows with it. Unfortunately, CR 2008 (or earlier for that matter) doesn't have this feature.
In image (below), I've added a text field above the cross-tab, but I can't think of a way to get it to grow/shrink (horizontally) with it.
If you're able to calculate, say by a summary function, the number of columns you will have then you can do this:
In your crosstab, check to see the width of your columns. The columns should be set widths. Edit: The crosstab adds some padding, so you will have to figure out the column width by measuring in Crystal with another field and eyeballing until it's close enough to work
Right-click on your label, and hit "Size & Position".
Add a new formula for the "Width". The X,Y positions should stay the same.
Use the summary function (You could create a SQL Expression or formula that only shows the month/year of your date fields and then distinctCount() them) to find out how many columns you will have multiplied by the width of each column. This will take some trial and error for sure, but I don't see why it wouldn't work.

How to set automatically min width of fields by longest text in some group

I use iReport to create reports, and I would like to know if there is a way to set the width of "optically grouped fields". They should be set to the minimal size that still displays longest text. I have Static Text on left side and Text Field right of them. This Text Fields are set to the width 150 and alignment to right, but I'd like to set smaller size to wipe out white spaces.
Consider some thing like this
Name: Paul
Surname: Smither
And want automatically to
Name: Paul
Surname: Smither
etc. can be smaller then preset size but no bigger.
Is there a way?? even some component
You cannot change the element width dynamically without using Java frameworks.
The quote from JasperReports Ultimate Guide:
ELEMENT SIZE
The width and height attributes are mandatory and represent the size
of the report element measured in pixels. Other element stretching
settings may instruct the reporting engine to ignore the specified
element height. Even in this case, the attributes remain mandatory
since even when the height is calculated dynamically, the element will
not be smaller than the originally specified height.
You can read this article for better understanding the mechanism of changing the element size.
If it's genuinely just a couple of fields that come from the same row in the dataset, then you could hack something together.
Use a monospace font
Define your maximum field length with a String set to N spaces. For example:
$P{MaxLengthString} default value is 10 spaces: " "
Change your field text from $F{FirstName} to this:
$P{MaxLengthString}.substring(
$P{MaxLengthString}.length() + $F{FirstName}.length() - java.lang.Math.max($F{FirstName}.length(), $F{LastName}.length())
) + $F{FirstName}
That is... er... a bit more complex. And it only works with monospace fonts. And I can't believe I really suggested this. Don't do it. (But it ought to work.)