0

I would like to underline one of the section title that appears at the center of the page, as shown in the figure:

enter image description here

I basically want to have an underline below one of the section (without altering the styling of the other sections) that is center aligned wrt to the section title. The length of the underline should be less than that of the section title as in the attached image. Is it possible to achieve this? Please note that I am using the following code snippet borrowed from here, to have a colored underline (I mentioned this to avoid conflict, if any, with the other packages that would be suggested in the answer) :

\documentclass[12pt,english]{article}
\usepackage[T1]{fontenc}
\usepackage[svgnames]{xcolor}
\usepackage{color,soul}
\setul{0.6mm}{0.2mm}
\setulcolor{red}
\usepackage{sectsty}
\sectionfont{\color{DarkBlue}\normalfont\fontsize{17}{18}\selectfont}

\begin{document}

\section*{\hfil Introduction \hfil} This is the \ul{underlined} text.

\end{document}

Aim
  • 633
  • 2
    Welcome to TeX.SX! Please make your code compilable (if possible), or at least complete it with \documentclass{...}, the required \usepackage's, \begin{document}, and \end{document}. That may seem tedious to you, but think of the extra work it represents for TeX.SX users willing to give you a hand. Help them help you: remove that one hurdle between you and a solution to your problem. Moreover, the answer on styling sectioning commands will depend heavily on the class/packages you use. – Rmano Mar 07 '21 at 17:34

2 Answers2

1

Your question is unclear and lacks important information. In any case below I try to propose a possible solution, which consists in creating a new command \redsection that prints the underlined section title, keeping the numbering of the normal sections:

\documentclass{article}
\usepackage{lipsum}
\usepackage{color}
\usepackage{soul}
  \setul{0.5ex}{0.3ex}
  \setulcolor{red}
\usepackage{aliascnt}
\usepackage{titlesec}

\newaliascnt{redsection}{section}

\DeclareRobustCommand{\redul}[1]{\ul{#1}}

\titleclass{\redsection}{straight}[\section] \titleformat{\redsection}[hang] {\Large\bfseries} {\thesection}{1em}{\redul} \titlespacing*{\redsection}{0pt}{3.5ex plus 1ex minus .2ex}{2.3 ex plus .2ex}

\begin{document} \section{A normal section} \lipsum[11]

\redsection{An automatic underlined section} \lipsum[11]

\section{\ul{A manual underlined section}} \lipsum[11] \end{document}

which gives:

enter image description here

Ivan
  • 4,368
0
\documentclass[12pt,english]{article}
\usepackage[T1]{fontenc}
\usepackage[svgnames]{xcolor}
\usepackage{sectsty}
\sectionfont{\color{DarkBlue}\normalfont\fontsize{17}{18}\selectfont}

\begin{document}

\section*{\hfil Introduction \hfil}
\vspace*{-4mm}
\hfil {\color{red} \rule{2cm}{0.2mm} } \hfil 

\end{document}

The lines \vspace*{-4mm} and \hfil {\color{red} \rule{2cm}{0.2mm} } \hfil produces the desired output. Although it's not one size fits all, the parameters of \vspace and \rule can be adjusted according to one's need.

Aim
  • 633