[Tex/LaTex] how to make unnumbered sections aligned in table of contents

sectioningtable of contents

I have the following code to create table of contents:

     \documentclass{article}

     \begin{document}

     \tableofcontents

     \section{section A}

     \addcontentsline{toc}{section}{section B}
     \section*{section B}

     \end{document}

Section B does appear in the TOC, but it appears unaligned with the text from section A, because there is no number preceding it. Is there a way to make section B go forward a bit, so that it is aligned?

EDIT: I would rather have someone that is "truly" aligned, instead of pushing it forward with blank spaces…

Best Answer

You can use the little package unnumberedtotoc which can be found on github at the moment. It just provides one option which will suit your needs; indentunnumbered. It also takes care or your marks. All this functionality is provided by the KOMA-classes by default. A switch might be worth it ;-)

\documentclass{article}
\usepackage[indentunnumbered]{unnumberedtotoc}%<-----
\begin{document}

\tableofcontents

\section{section A}

\addsec{section B}

\end{document}