[Tex/LaTex] Section and subsection numbering

numberingsectioningtitlesec

I'm new to LATEX language and now a have a problem with section and subsection numbering.
I want to make my text look like this:

1. Sun

1.1 Moon

2. Bed

I was tried to figure out how to make it, but it doesn't work for me.
This is my code:

 \documentclass[12pt,a4paper,oneside]{article}
\usepackage{titlesec}
\titleformat{\section}[block]{\Large\bfseries\filcenter}{}{1em}{}
\titleformat{\subsection}[hang]{\bfseries\filcenter}{}{1em}{}
\renewcommand{\thesection}{\arabic{section}}
\begin{document}
\section{Sun}
\subsection{Moon}
\section{Bed}
\end{document}

Best Answer

You need to pass the appropriate counter to the third required argument of \titleformat. Currently you just have written {} instead of e.g. {\thesection}. Here is a complete example, with left alignment rather than centering:

Sample output

\documentclass[12pt,a4paper,oneside]{article}

\usepackage{titlesec}

\titleformat{\section}[block]{\Large\bfseries\filright}{\thesection}{1em}{}
\titleformat{\subsection}[hang]{\bfseries\filright}{\thesubsection}{1em}{}

\begin{document}
\section{Sun}
\subsection{Moon}
\section{Bed}
\end{document}
Related Question