QGIS custom grid overlapping in printing layout

expressiongrids-graticulesprint-composerqgis

I've set my custom grid in the print layout. The problem is, that in one corner both values from X and Y axes overlap each other.

enter image description here

I used the offset, as you can see below, but I am wondering how to make this only one value offset more than the rest.

I found some similar problems here:

Stop Grid Coordinates Overlapping in Print Layout

which led me to the bug here:

https://github.com/qgis/QGIS/issues/45876

My formula for custom grids looks like this:

CASE 
  WHEN @grid_axis = 'y'
    THEN substr('ABCDEFGHIJKLMNOPQRST', (@grid_number +105) / 100, 1) 
  WHEN @grid_axis = 'x'
    THEN round((@grid_number - 5) / 100,0)
END

And I obviously can change it simultaneously with the offset bringing them up, although I tried the solution, which would led offset just only the first value at the Y axis.

The formula I prepared looks like this:

CASE 
  WHEN @grid_axis = 'y' AND @grid_number = 'A' THEN offset = 15
END

but it stays as it is despite lack of error in the formula.

How can I offset only this one value separately?

Regarding my situation with interval 100 and offset 7 I tried also:

CASE 
  WHEN @grid_axis = 'y' AND substr('ABCDEFGHIJKLMNOPQRST', (@grid_number = 0) / 100, 1)   THEN OFFSET = 15
END

UPDATE:

I think the problem lies with the "Distance to the map frame" issue. As I set it to 5mm then the overlapping occurs. What kind of formula should I place inside then?

enter image description here

I could reduce the distance from the map frame, although with the font size I applied (24px) it still won't work.

enter image description here

Best Answer

After some experimentation it appears that the distance to frame cannot be set independently for the X and Y axes.

Here is my label grid set up. I chose Outside frame for the labels so there were legible.

enter image description here

Using a Distance to frame of 5 mm and the formula:

(@grid_axis || @grid_number)

to show the grid axis and grid number in the label itself so there can be no confusion.

enter image description here

Then for Distance to frame I used the formula

CASE 
  WHEN @grid_axis = 'y' then 20
  WHEN @grid_axis = 'x' then 0
END

Both sets of labels end up at 0 mm distance.

enter image description here

A formula using @grid_number

CASE 
  WHEN @grid_number < 10 then 20.0
  ELSE 0
END

enter image description here


Separate note about one of your formulae

The formula I prepared looks like this:

CASE    
   WHEN @grid_axis = 'y' AND @grid_number = 'A' 
   THEN offset = 15 
END 

but it stays as it is despite lack of error in the formula.

The @grid_number is never going to be A, so this formula, despite having no errors, will not evaluate. The @grid_number is always an integer and it is tied to the grid interval. The first grid square contains 100 grid numbers for each axis (1-100, 100 being your interval in mm). As seen in the image directly above, the displayed grid number for this particular set of labels is the interval 0, 100, 200, etc + the offset 6 for the x axis and + 7 for the y axis. The rest of the grid numbes still exist, but they just have no label.

Related Question