[Tex/LaTex] How to center part,section,… (LyX)

lyxsections-paragraphs

How Can I center a part or a section in LyX?
I saw this question – Center part title in Lyx – but I want to know to do it every time without write any part, section,… \begin{center}...\end{center}

It is possible?
Thank you!

Best Answer

In LyX itself, I don't know, but you can delve into the underlying code and write in the preamble:

\usepackage{titlesec}
\titleformat*{\part}{\centering}
\titleformat*{\section}{\centering}

For more complex changes you'll have to use the \titleformat command (without a star), which has 4 mandatory and 1 optional arguments.

Edit: Here is an ‘advanced’ code:

\titleformat{\part}[display]{\filcenter\huge\bfseries}{\partname \thepart}{4ex} {}
\titleformat{\section}[block]{\filcenter\LARGE\bfseries} {\thesection.}{0.5em}{}