[Tex/LaTex] Section numbers behind section title

sectioningtitlesec

I'm an absolute newbie to TeX. I'm trying to get the section numbers of a section to be at the end of the title. In other words, something like "Question 4.2". Instead I get "4.2 Question 4.2" which is not great. Also, the numbers should follow with indentation. For example:

Question 4.2
  4.2.1 ....
  4.2.2 ....

Any ideas how I can accomplish this?

Best Answer

You can change the format of the sections using the titlesec package. The indention of the subsections can also be done with it. However, I'm not 100% sure what you exactly mean with Also, the numbers should follow with indentation.

\documentclass{book}

\usepackage{titlesec}

\titleformat{\section}{\normalfont \Large \bfseries}
{Question\ \thesection}{2.3ex plus .2ex}{}
\titlespacing{\subsection}{2em}{*1}{*1}

\begin{document}

\chapter{X}

\section{A}
\subsection{a}
\subsection{b}
\section{B}
\end{document}

Result:

Result