Hello,
as Bartman said in the other topic about the font issue, please always provide a
minimal working example that contains the problem, because then we can test and fix or improve it. Otherwise ever reader has to type a whole document to provide a solution that's tested and works. I did this one time now, please next time show it with a small but complete code like this:
Code: Select all
\documentclass{report}
\usepackage{titlesec}
\newcommand*{\myalignment}{\centering}
\titleformat{\section}{\bfseries\Large\myalignment}{\thesection.}{0.1cm}{}
\begin{document}
\chapter{One}
\section{Centered heading}
\renewcommand*{\myalignment}{\raggedright}
\section{Left aligned heading}
\renewcommand*{\myalignment}{\centering}
\section{Another centered heading}
\end{document}
Here you can see how one may do it as one possible way. By the way I replaced
\hspace{0.1cm}
by
0.1cm
since at that point a length value is expected, not a space command.
You can see an advantage of a complete code example here: one can edit and compile it right here in the forum by clicking the "Run LaTeX here" button. So one can run LaTeX for testing the code even on a phone. Code is marked by selectin it and clicking the "Code" button, when editing a post here.
Stefan