# How to center part,section,… (LyX)

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!

• Did you try using \sectionfont{\centering} and \subsectionfont{\centering} to center the section and subsection headings? – leandriis Apr 14 '18 at 16:51
• @leandriis - it's doesn't recognize it.. :-( – heblyx Apr 14 '18 at 21:15

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}{}

• I think the only LyX-specific instruction would be to put the above commands in Document > Settings > LaTeX Preamble – scottkosty Apr 14 '18 at 18:27
• It's give an error. it says: Package titlesec Error: Not allowed in `easy' settings. What can I do? – heblyx Apr 14 '18 at 21:34
• Could you post a full compilable code producing this error? I tested this solution with a minimal code before posting, so probably there's something else which is not compatible with this code. – Bernard Apr 14 '18 at 21:38
• @Bernard - Sure! this is the error: anotepad.com/notes/j2tg7h – heblyx Apr 15 '18 at 8:43
• And here is the full code of the document - anotepad.com/notes/47bsmc – heblyx Apr 15 '18 at 8:45