1

I have a problem with the section headings using the titlesec-package. I want to have all the titles left-aligned. However, when I write longer titles such as "Peer-reviewed Publications" then "Peer-reviewed" is left-aligned and "Publications" is right-aligned with a big gap in between. How can I bring the whole title to the left-hand sinde?

\documentclass{article}
\usepackage {currvita}
 \usepackage{ragged2e}
 \usepackage[margin=1in]{geometry}
 \usepackage{titlesec}
 \thispagestyle{empty}

\titleformat{\section}
  {\normalfont\Large\bfseries}{\thesection}{1em}{}[{\titlerule[2pt]}]

\begin{document}
\date{}
\centering 
\begingroup
    \fontsize{15pt}{15pt}\selectfont
\textbf{sdfsdf} 
\endgroup

\raggedright
\section*{Education} 

\section*{Peer-reviewed Publications} 

2 Answers 2

1

You're misusing \centering and \raggedright.

It's generally not recommendable to use \centering at the top level, because it's hard to get back to normal typesetting. A general rule with LaTeX is to use grouping for such changes. However, just interchanging \centering and \begingroup would not do, because the text would end up justified. Much better is to use the center environment.

While \raggedright may be used at the top level, if one wants ragged right typesetting, you have to help titlesec, because it doesn't assume it and, as you saw, it produces wrong results.

My suggestion is to use standard justified typesetting.

\documentclass{article}
\usepackage{currvita}
\usepackage{ragged2e}
\usepackage[margin=1in]{geometry}
\usepackage{titlesec}

\titleformat{\section}
  {\normalfont\Large\bfseries}
  {\thesection}
  {1em}
  {}
  [{\titlerule[2pt]}]

\setcounter{secnumdepth}{-2}

\begin{document}

\thispagestyle{empty}

\begin{center}
\Large\bfseries
sdfsdf
\end{center}

\section{Education}

\section{Peer-reviewed Publications}

\end{document}

enter image description here

Since you seem to be using unnumbered sections throughout, instead of \section* it's better to set the counter for the numbering depth.

Finally, using \fontsize{15pt}{15pt} is wrong in several aspects. The first of which is that you don't get a 15pt font (you find a warning in your log file); second, the distances between lines would appear to be random.

0
0

Just add a \raggedright to the \titleformat:

\documentclass{article}
\usepackage {currvita}
 \usepackage{ragged2e}
 \usepackage[margin=1in]{geometry}
 \usepackage{titlesec}
 \thispagestyle{empty}

\titleformat{\section}
  {\normalfont\Large\bfseries\raggedright}{\thesection}{1em}{}[{\titlerule[2pt]}]

\begin{document}
\date{}
\centering 
\begingroup
    \fontsize{15pt}{15pt}\selectfont
\textbf{sdfsdf} 
\endgroup

\raggedright
\section*{Education} 

\section*{Peer-reviewed Publications} 
\end{document}
1
  • You can use the \filright command defined by the package. I suppose it must do something more than \raggedright in this context.
    – Bernard
    Jul 24, 2017 at 22:12

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .