decoration the title of section

decoration the title of section

I want to add a line segment of about 3 cm that follows the title of section in my book. How can you modify the following code? I add \rule{3cm}{.45pt} in but it notices capacity exceeds.

\documentclass[oneside,11pt]{book}

\usepackage{siunitx}
\usepackage{fancybox} 
\usepackage{pgf,tikz}
\usepackage[textwidth=16.25cm,textheight=19cm]{geometry} %kho sach 18x23

\usepackage[mathscr]{eucal}
\usepackage{graphics, graphpap}

\begin{document}
\tableofcontents
\chapter{First Chapter}

\pagebreak
\section{Perimeter {\rule{3cm}{.45pt}} }

\begin{enumerate} 
\item first item
\item second item

\end{enumerate}
\end{document}

답변1

Without any packages: Make a quick and dirty redefinition of \@sect, the underlying macro for the \section etc. commands.

The redefinition checks whether section or another subsection etc is used and then applies the \rule.

Change the \ruledistskip length at will...

\documentclass[oneside,11pt]{book}

\usepackage{siunitx}
\usepackage{fancybox} 
\usepackage{pgf,tikz}
\usepackage[textwidth=16.25cm,textheight=19cm]{geometry} %kho sach 18x23

\usepackage[mathscr]{eucal}
\usepackage{graphics, graphpap}

\newlength\ruledistskip
\setlength{\ruledistskip}{5em}

\makeatletter
\let\l@tex@sect\@sect
\def\@sect#1#2#3#4#5#6[#7]#8{%
  \l@tex@sect{#1}{#2}{#3}{#4}{#5}{#6}[#7]{#8\ifnum0=\pdfstrcmp{#1}{section}%
    \hskip\ruledistskip\rule{3cm}{.45pt}%
    \fi}%
}
\makeatother
\begin{document}


\tableofcontents
\chapter{First Chapter}

\clearpage
\section{Perimeter}

\subsection{Ruleless}

\begin{enumerate} 
\item first item
\item second item

\end{enumerate}
\end{document}

enter image description here

관련 정보