0

I want to add a custom short line in the right of my subsection as shown below: The article I want

Here is my .tex, how could I add the short blue line in the subsetion right side, and not display in Contents?

\documentclass{article}

\usepackage{lipsum}

\renewcommand{\thesection}{\arabic{section}.}
\renewcommand\thesubsection{\arabic{section}.\arabic{subsection}.}

\begin{document}
    \tableofcontents 

    \section{section1}
    \subsection{subsection1}
    \lipsum[1]

    \subsection{sub2}
    \lipsum[2]
\end{document}

1 Answers1

2

Combination of How to create a header line after text, A horizontal line with the same space-filling behaviour as /hfill?, how to add number to the title of sections and subsection using the titlesec package

MWE:

\documentclass{article}
\usepackage[explicit]{titlesec}
\usepackage{xhfill}
\usepackage{lipsum}

\titleformat{\section}
  {\normalfont\Large\bfseries}{\thesection}{1em}{#1~\xrfill[0.3ex]{1.5pt}[blue]}
\titleformat{\subsection}
  {\normalfont\large\bfseries}{\thesubsection}{1em}{#1~\xrfill[0.3ex]{1.5pt}[blue]}

\begin{document}
    \tableofcontents 

    \section{section1}
    \subsection{subsection1}
    \lipsum[1]

    \subsection{sub2}
    \lipsum[2]
\end{document}

Result:

enter image description here

Marijn
  • 37,699
  • You obtain the same result without any extra package replacing \xrfill[0.3ex]{1.5pt}[blue] with \color{blue}\titlerule[0.3ex]. – Bernard Jun 27 '16 at 09:45