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

1 Answer 1

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

1
  • 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, 2016 at 9:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.