# How to center section when using \titleformat{\section}?

I decided to use \usepackage[center]{titlesec} in order to center my sections, but I don't want them displaying the chapter/section numbering in the chapter/section headings so I applied the titleformat. But with this new macro, it erased the [center] command.

\documentclass[14pt]{memoir}

\usepackage[center]{titlesec}
\usepackage{lipsum}

\titleformat{\chapter}
{\Large\bfseries}
{}
{0pt}
{\huge}

\titleformat{\section}
{\Large\bfseries}
{}
{0pt}
{\large}

\begin{document}

\tableofcontents

\chapter{This shouldn't be centered}
\clearpage
\section{This should be centered}
\lipsum[1]
\subsection{This should be centered}
Nothing to see here.
\end{document}


Result:

• It worked but generated a /par error on compilation. – Xyd Jan 19 '16 at 18:56
• – egreg Jan 19 '16 at 18:57

like this ? :

\documentclass[14pt]{memoir}

\usepackage[center]{titlesec}
\usepackage{lipsum}

\titleformat{\chapter}
{\centering\Large\bfseries} % format
{}% label
{0pt} % sep
{\huge}

\setcounter{secnumdepth}{0}

\begin{document}

\tableofcontents

\chapter{This shouldn't be centered}
\clearpage
\section{This should be centered}
\lipsum[1]
\subsection{This should be centered}
Nothing to see here.
\end{document}


Result:

• I tried it and saw that \chapter{This shouldn't be centered} actually centered. Oh well but once I removed \centering it was all good!... But the numbers came back. – Xyd Jan 19 '16 at 18:56
• I found an answer elsewhere and used \setsecnumdepth{none} \maxsecnumdepth{none} instead of \setcounter{secnumdepth}{0} and now it worked (as for removing the darn numbers). – Xyd Jan 19 '16 at 19:18

You shouldn't use titlesec with memoir, see About memoir and titlesec incompatibility

\documentclass[14pt]{memoir}

\usepackage{lipsum}

\setsechook{\setsecnumformat{\csname the##1\endcsname\ }}

\begin{document}

\tableofcontents

\chapter{This shouldn't be centered}
\section{This should be centered}
\lipsum[1]
\subsection{This should be centered}
Nothing to see here.
\end{document}