I'm using the extarticle
class and I want to have a \subtitle
command to add subtitles for sections. Here's what I expected:
Here is my current solution, quite ugly to be frank:
\documentclass{extarticle}
\usepackage{titlesec}
\makeatletter
\newlength{\fsizept}
\setlength{\fsizept}{\f@size pt}
\makeatother
\newlength{\titleruleheight}
\setlength{\titleruleheight}{0.075\fsizept}
\titleformat{\section}{\Large\sffamily}
{\thesection}{1em}{}[{\titlerule[\titleruleheight]}]
\newlength{\subtitleposfix}
\setlength{\subtitleposfix}{-2\baselineskip} %This should be linked with font size.
\newcommand\subtitle[1]{
\vspace{\subtitleposfix}%
\begin{flushright}%
\emph{\emph{------}#1}%
\end{flushright}\par}
\begin{document}
\section{The title}
\subtitle{The subtitle}
\end{document}
I find it hard to correctly align the title and subtitle. The 2\baselineskip
above is just an inaccurate approximation. The real value should depend on font size and configurations of the titlerule
(as you can see, this titlerule
depends on the font size given by \fsizept
).
I should add that I did some searches for existing questions such as this one. But I didn't find a satisfied solution for my case.
Anyway, is there a better way to achieve this?