如何定义具体的宏?

如何定义具体的宏?

创建新的标题样式,我如何创建宏来实现这一点:

enter image description here

我想在书的每一章末尾使用它。

答案1

可以通过测量文本的宽度并从线宽中减去该宽度来计算规则的宽度。

可以根据堆叠的规则绘制线条\vcenter,将内容围绕数学轴居中。

例子:

\documentclass{article}
\usepackage{color}

\newcommand*{\EndChapter}[1]{%
  \par
  \noindent
  \begingroup
    \sbox0{\bfseries\ #1\ }%
    \dimen0=.5\dimexpr\linewidth-\wd0\relax
    \BlueLines{\dimen0}%
    \usebox0%
    \BlueLines{\dimen0}%
  \endgroup
}
\newcommand*{\BlueLines}[1]{%
  $%
    \mathsurround=0pt %
    \color{blue}%
    \vcenter{%
      \hrule width#1 height\BlueLinesThickness
      \kern\BlueLinesSep
      \hrule width#1 height\BlueLinesThickness
      \kern\BlueLinesSep
      \hrule width#1 height\BlueLinesThickness
      \kern\BlueLinesSep
      \hrule width#1 height\BlueLinesThickness
      \kern\BlueLinesSep
      \hrule width#1 height\BlueLinesThickness
    }%
  $%
}
\newdimen\BlueLinesThickness
\setlength{\BlueLinesThickness}{2pt}
\newdimen\BlueLinesSep
\setlength{\BlueLinesSep}{1.5pt}

\begin{document}
\EndChapter{Problems of Week 1}
\end{document}

Result

相关内容