# Section and subsection numbering

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}


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:

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

• +1, but you may omit \filright (and use the hang format for both sectioning levels). – lockstep Aug 1 '13 at 9:22
• @lockstep indeed - the user's needs are quite clear, so I left the \filright so it could easily be switched back to the centering version. – Andrew Swann Aug 1 '13 at 9:24