如何在 \section* 前方放置一個彩色框

如何在 \section* 前方放置一個彩色框

我正在使用 Jesper Ipsen 提供的 MWE以下問題

我打算使用彩色框而不是部分編號。我的想法是實現它如下面的問題所示

現在唯一要做的就是在我創建新部分時有一個簡單的方法來添加這些框,如下所示:

\section*{Time Machines}

我們的想法是讓它看起來像這樣:

在此輸入影像描述

答案1

正如 skpblack 評論的那樣,包titlesec可以用於此目的:

\documentclass{article}

\usepackage{lmodern, titlesec, xcolor}

\titleformat{name=\section,numberless}
{\normalfont\Large\bfseries}
{\color{yellow}\rule{1em}{1em}}
{1em}
{}


\begin{document}

\section{Another day in paradise}

A regular numbered section

\section*{Another night in paradise}

A starred section that has a coloured box

\end{document}

這使

在此輸入影像描述

有關間距等的微調,請參閱titlesec文件。

相關內容