How to create a table of sign?

Hello,
I try to help my son creating a clean doc for his math homework. We needs to create a table of signs (direct translation from french, sorry, it may be the reason why I struggle to find solution here or on google).
It looks like this :


The solution may be using a complicated table.cell(colspan:) structure, but I wonder if there’s a more elegant solution.
Also, I can’t find a solution for the « 0 » across the vertical lines…
Thank’s a lot,
Olivier.

Hey @nemolivier, welcome to the forum! I’ve updated your post title to better suit our question post guidelines: How to post in the Questions category

Make sure your post title is a question you’d ask to a friend about Typst. :wink:


Here’s an example based on something I’ve made before. Note that we use 0pt columns for the interval limits. Feel free to customize and use it as much as you want:

#show table.cell: it => {
  if it.x > 0 and it.y > 0 {
    show "+": set text(green.darken(5%))
    show $-$.body.text: set text(red.darken(15%))
    show "0": set text(gray)
    it
  } else {
    set text(blue.darken(20%))
    it
  }
}

#table(
  columns: (auto, auto, 0pt, auto, 0pt, auto, 0pt, auto),
  align: (x, y) => if y == 0 { center + bottom } else { center },
  stroke: (x, y) => (
    // Dash stroke inside
    right: if x > 0 and y > 0 { (paint: black, dash: "dotted") },
    // Left border
    left: if y > 0 and x == 1 { black },
    // Top border
    top: if x > 0 and y == 1 { black },
    rest: none),
  $x$, [], $-oo$, [], $5$, [], $10$, [],

  // Right border
  table.vline(start: 1, stroke: (dash: none)),

  $f$, $-$, [], $+$, [], $-$, [], $+$,
  $g$, $+$, [0], $+$, [], $+$, [], $+$,
  $h$, $-$, [], $+$, [], $-$, [], $+$,
  $m$, $+$, [], $+$, [], $+$, [], $+$,

  // Have to place bottom border manually
  // to avoid having to somehow fetch the amount of rows
  table.hline(start: 1, stroke: (dash: none))
)

output: sign table

1 Like

Hello @PgBiel ,
Many thanks for the quick and gentle answer.
(I do have read the guideline, sorry it was not enough).
Your answer is very complete and helpful (0 pt columns, I like that :grinning:), I’m going to take time to understand all this (and making my son understand it too !!)
Hope this help other people.
Regards,
Olivier.

1 Like