[Tex/LaTex] “Package titlesec Error: Entered in horizontal mode” error

titlesec

I am having issues with the error. Although it does not affect generating texts, it bugs me. I have a sense that there is something wrong with \titleformat lines. I have tried to solve the issue by myself by reading some related documents, but they did not work.

Thank you.

\documentclass[11pt,a4paper]{article}

\usepackage[utf8]{inputenc}
\usepackage{authblk}
\usepackage[colorinlistoftodos]{todonotes}
\date{}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{bm}
\usepackage{fancyhdr}
\usepackage[margin=1in, total={8.5in, 11in}]{geometry}

\usepackage{graphicx}
\usepackage{float}
\usepackage{caption}
\usepackage{subcaption}
\usepackage{multicol}
\usepackage{adjustbox}
\usepackage{xcolor}
\numberwithin{equation}{section}
\usepackage{epstopdf}
\usepackage{enumitem}
\usepackage{titlesec}
\usepackage{setspace} 
\usepackage{indentfirst}

\bibliographystyle{plain}
\usepackage[superscript]{cite}
\usepackage{helvet}
\usepackage{ragged2e}
\renewcommand{\familydefault}{\rmdefault}


\titleformat{\section}[hang]{\centering\normalfont\large\bfseries}{}{1pt}{}
\titleformat{\subsection}[hang]{\normalfont\large\bfseries\itshape\underline}{}{1pt}{}
\titleformat{\subsubsection}[hang]{\normalfont\large}{}{1pt}{}





\begin{document}

\begin{titlepage}
\begin{center}
\end{titlepage}
\section*{SUMMARY}
\addcontentsline{toc}{section}{\numberline{}Summary}    
\section*{ACKNOWLEDGEMENTS}

\section*{INTRODUCTION}
\subsection*{Background and Motivation}

\paragraph{xxxxxxx}


\subsection*{Hypotheses}
\subsection*{Scope}
\subsection*{Approaches}
\subsection*{Project Objectives}

\section*{PROJECT TECHNICAL PLANS}
\subsection*{Description of Methods}
\paragraph{[1] Project }
\subparagraph{xxx}
\subparagraph{xxx}  
\subparagraph{xxx}    

\paragraph{[2] Project}
 \subparagraph{xxx}
\subparagraph{xxx}  
\subparagraph{xxx}    

\paragraph{[3] Project}
 \subparagraph{xxx}
\subparagraph{xxx}  
\subparagraph{xxx}    



\subsection*{Project Schedule}
\subsection*{Preliminary Results}

\paragraph{[1] xxx}
\paragraph{[2] xxx}
\paragraph{[3] xxx}

\section*{EXPECTED RESULTS}
\subsection*{Statement of Potential Contributions}
\subsection*{Discussion of Alternative Approaches}
\subsection*{Timeline of Milestones}
\subsection*{Publication Plans}
\section*{PROJECT MANAGEMENT}
\subsection*{Equipment Training and Safety Plan}
\subsection*{Materials Storage and Disposal}
\subsection*{Authentication of key resources}
\subsection*{Data management plan}

\section*{REFERENCES}

\end{document}

enter image description here

Best Answer

The problem was in the \underline command, which requires an argument, and thus canused only in the last argument of titleformat. Also begin{center} for the titlepage environment had no corresponding \end{center}. This code works:

\documentclass[11pt,a4paper]{article}

\usepackage[utf8]{inputenc}
\usepackage{authblk}
\usepackage[colorinlistoftodos]{todonotes}
\date{}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{bm}
\usepackage{fancyhdr}
\usepackage[margin=1in, total={8.5in, 11in}]{geometry}

\usepackage{graphicx}
\usepackage{float}
\usepackage{caption}
\usepackage{subcaption}
\usepackage{multicol}
\usepackage{adjustbox}
\usepackage{xcolor}
\numberwithin{equation}{section}
\usepackage{epstopdf}
\usepackage{enumitem}
\usepackage{titlesec}
\usepackage{setspace}
\usepackage{indentfirst}

\bibliographystyle{plain}
\usepackage[superscript]{cite}
\usepackage{helvet}
\usepackage{ragged2e}
\renewcommand{\familydefault}{\rmdefault}

\titleformat{\section}[hang]{\filcenter\normalfont\large\bfseries}{}{1pt}{}
\titleformat{\subsection}[hang]{\normalfont\large\bfseries\itshape}{}{1pt}{\underline}
\titleformat{\subsubsection}[hang]{\normalfont\large}{}{1pt}{}

\begin{document}

\begin{titlepage}
\begin{center}
\end{center}
\end{titlepage}
\section*{SUMMARY}
\addcontentsline{toc}{section}{\numberline{}Summary}
\section*{ACKNOWLEDGEMENTS}

\section*{INTRODUCTION}
\subsection*{Background and Motivation}

\paragraph{xxxxxxx}

\subsection*{Hypotheses}
\subsection*{Scope}
\subsection*{Approaches}
\subsection*{Project Objectives}

\section*{PROJECT TECHNICAL PLANS}
\subsection*{Description of Methods}
\paragraph{[1] Project }
\subparagraph{xxx}
\subparagraph{xxx}
\subparagraph{xxx}

\paragraph{[2] Project}
 \subparagraph{xxx}
\subparagraph{xxx}
\subparagraph{xxx}

\paragraph{[3] Project}
 \subparagraph{xxx}
\subparagraph{xxx}
\subparagraph{xxx}

\subsection*{Project Schedule}
\subsection*{Preliminary Results}

\paragraph{[1] xxx}
\paragraph{[2] xxx}
\paragraph{[3] xxx}

\section*{EXPECTED RESULTS}
\subsection*{Statement of Potential Contributions}
\subsection*{Discussion of Alternative Approaches}
\subsection*{Timeline of Milestones}
\subsection*{Publication Plans}
\section*{PROJECT MANAGEMENT}
\subsection*{Equipment Training and Safety Plan}
\subsection*{Materials Storage and Disposal}
\subsection*{Authentication of key resources}
\subsection*{Data management plan}

\section*{REFERENCES}

\end{document}
Related Question