Do we have alternative to LaTeX titlesec/titlespacing?

In latex we can use titlesec, do have so similar one in typst?

\usepackage{titlesec}
\titlespacing{\chapter}{0pt}{*1}{*1}
\titlespacing{\section}{0pt}{*1}{*1}
\titlespacing{\subsection}{0pt}{*1}{*1}

\titlespacing{\subsubsection}{0pt}{*1}{*1}

It will setting the left margin for all major section types to 0pt, and keeping the usual vertical space above and below them

Hi, can you describe what the code does or you want to achieve, not everyone here speaks latex. Thanks.

3 Likes

Hello @chaos1 , since users on the forum here may not be as fluent in LaTeX as you may be, could you please describe or provide a visual example of what you are looking for?

This in order to try to help you best. Thanks!:pray:

3 Likes

Hi chaos1! I’ve also used titlesec before. It always meets my requirement, but I can never tell what each specific parameter does later, especially in the old days before LLMs.

It will setting the left margin for all major section types to 0pt, and keeping the usual vertical space above and below them

So that is basically:

#outline(indent: 0em)

// Or if you want to change the style without actually creating the outline now:
#set outline(indent: 0em)
1 Like

To set the vertical spacing the block element, which is used internally by headings, provides the above and below properties and spacing to set both simultaneously.

#show heading.where(level: 1): set block(above: 3cm, below: 3cm) //or spacing: 3cm

To inset the heading from the left, you can use pad.

#show heading.where(level: 1): pad.with(left: 30pt)

I hope that helps, and I understood the question correctly.

3 Likes

Thanks so much! One more question, if we have multiple lines for the heading, how can we set the space within the lines elegantly?

You could change par.leading.

#show outline: set par(leading: 0.4em):

Default (0.65em):

I mean somecase like this: the heading is too long that consumes two lines:


#set par(first-line-indent: (amount: 2em, all: true), leading: 1.5em)

= #zhlorem(42)
#zhlorem(200)

I currently use


#show heading: it => {
  set par(leading: 1em)
  set text(spacing: 0.5em)
  it
}

I recommend the following

#show heading: set par(leading: 1em)
#show heading: set block(below: 100000em) // Change as you wish

text.spacing controls the horizontal space between space-separated words. It makes no sense here.


Additionally, please use show-set rules in favor of show-function rules whenever possible.
Occasionally, you might want to override your previous rules. In that case, writing another show-set rule just works, while writing another show-function rule will get them nested.


More info: Which show rule takes precedence? - #15 by Y.D.X


Besides, since you write Chinese, maybe the following basic intro would help.

2 Likes