How do I offset tick labels in CeTZ?

I want to offset the x-tick labels (x_1, x_2 and x_3) only by a y value (make them lower) on the plot.

#align(center)[
  #cetz.canvas({
    import cetz.draw: *
    import cetz-plot: *

    set-style(
      axes: (
        y: (stroke: 0pt),
        // x: (stroke: 0pt),
        tick: (stroke: 0pt),
        padding: 0pt,
      ),
      
    )

    plot.plot(
      size: (10,2),
      axis-style: "school-book",
      x-tick-step: none, 
      y-tick-step: none, 
      x-ticks: range(10).map(n => (n+1, [])),
      x-label: [],
      y-label: none,
      x-min: 1, x-max: 7,
      y-min: -1, y-max: 1,
      
      axes: (
        stroke: black,
        tick: (stroke: 0pt),
      ),
      name: "plot",
    {
      plot.add(((0,0), (3,0)), style: (stroke: none))

      plot.annotate({
        rect(
          (1.05,-0.3), 
          (2.95, 0.3), 
          fill: blue.lighten(60%),
          // radius: 1pt
        )
        content((2, 0), [3])
      })

      plot.annotate({
        rect(
          (3.05,-0.3), 
          (3.95, 0.3), 
          fill: blue.lighten(60%),
          // radius: 1pt
        )
        content((3.5, 0), [1])
      })
      
      plot.annotate({
        rect(
          (4.05,-0.3), 
          (5.95, 0.3), 
          fill: blue.lighten(60%),
          // radius: 1pt
        )
        content((5, 0), [2])
      })

      plot.annotate({
        rect(
          (6.05,-0.3), 
          (6.95, 0.3), 
          fill: gray.lighten(60%),
          // radius: 1pt
        )
      })
      
    }
  )
  })
]

More generally, where do I find all the set-style options that are available to me?

Hi!

The option you’re looking for is tick.label.offset.

Since the online documentation for cetz-plots isn’t available yet, you’ll need to refer to the old CeTZ Manual.pdf.

set-style(
      axes: (
        y: (stroke: 0pt),
        x: (tick: (label: (offset: 1cm))),
        tick: (stroke: 0pt),
        padding: 0pt,
      ),      
    )

CeTZ 0.2.2.pdf (703.7 KB)

I’d open an issue about missing documentation, if it’s not present.

There is an up-to-date cetz-plot documentation in PDF format here: https://raw.githubusercontent.com/cetz-package/cetz-plot/refs/heads/master/manual.pdf

1 Like