
我希望我的文件有如下所示的章節標題:
我怎樣才能在 LaTeX 中實現這一目標?
答案1
對於您的最終解決方案,根據需要定義深紅色,並在我的提案中將其替換為“紅色”。請注意,在下面的範例中,給定的設計也適用於部分格式。
程式碼
\documentclass[11pt]{article}
\usepackage{lipsum}
\usepackage{xcolor}
\usepackage{titlesec}
\titleformat{\section}
{\normalfont\Large\itshape\color{red}}{%
\hspace*{-4.5em}\rule[-1.35mm]{4.5em}{1.25em}
{\color{white}\hspace{-1cm}\normalfont\thesection\hspace{5pt}}
}{1em}{}
\titleformat{\subsection}
{\normalfont\large\itshape\color{red}}{%
\hspace*{-4.5em}\rule[-1.35mm]{4.5em}{1.25em}
{\color{white}\hspace{-1cm}\normalfont\thesubsection\hspace{5pt}}
}{1em}{}
\begin{document}
\section{Introduction}
\lipsum[1]
\subsection{Laplace Transformation}
\lipsum[2-4]
\end{document}