根据 MWE,我目前使用两种类型的部分标题栏:用于普通未编号部分(MWE 中的“osections”)的圆角灰色条和用于编号部分的“主题 N”(其中 N = 部分编号)
我想使用 tikz 节点添加另一种“类型”的标题栏,即“摘要”:
有人能给我指出正确的方向吗?
% MWE,按照http://glurl.co/dFH
\documentclass[a5paper]{memoir}
\setsecnumdepth{section}
\maxsecnumdepth{section}
\usepackage{color,calc,graphicx,soul,fourier}
\definecolor{topic}{rgb}{.125,.125,.500} %
\definecolor{info}{rgb}{.125,.125,.500} %
\usepackage[explicit]{titlesec}
\usepackage{tikz}
\usetikzlibrary{shapes.misc}
\makeatletter
\let\currentsectiontitle\relax
\newcommand\titlebar@{%sections
\tikz[baseline,trim left=3.1cm,trim right=3.15cm] {
\fill [black!15] (2.5cm,-1ex) rectangle (\textwidth+3.1cm,2.5ex);
\node [fill=black!15!white,
anchor= base east,
rounded rectangle,
minimum height=3.5ex] at (2.8cm,0.13) {};
\node [fill=black!100!white, anchor= base east, rounded rectangle,
minimum height=3.75ex] at (14cm,0.05) {
\color{white}{Topic \thesection}};
}}
\newcommand\titlebar@@{%osections
\tikz[baseline,trim left=3.1cm,trim right=3.15cm] {
\fill [black!15] (2.5cm,-1ex) rectangle (\textwidth+3.6cm,2.5ex);
\node [fill=black!15!white, anchor= base east, rounded rectangle,
minimum height=3.5ex] at (2.8cm,0.13) {};
\node [fill=black!15!white, anchor= base east, rounded rectangle,
minimum height=3.5ex] at (13.5cm,0.13) {};
}}
\newcommand\stitlebar@@{%ssections
\tikz[baseline,trim left=3.1cm,trim right=3.15cm] {
\fill [black!15] (2.5cm,-1ex) rectangle (\textwidth+3.6cm,2.5ex);
\node [fill=black!15!white, anchor= base east, rounded rectangle,
minimum height=3.5ex] at (2.8cm,0.13) {};
\node [fill=black!100!white, anchor= base east, rounded rectangle,
minimum height=3.5ex] at (14.0cm,0.03) {
\color{white}{Summary}};
}}
\newcommand\titlebar{\@ifstar\titlebar@@\titlebar@}
\titleformat{\section}{\large\bfseries}{\titlebar}
{0.1cm}{\gdef\currentsectiontitle{#1}#1}
\renewcommand*{\thesection}{\arabic{section}}
\newcommand{\osection}[1]{\section*{\titlebar*#1}}
\newcommand\summary{\stitlebar@@}
\newcommand{\ssection}[1]{\section*{\summary#1}}
\makeatother
\begin{document}
\pagestyle{empty}
\osection{Ordinary Section Header}
This is for ordinary sections.
\section{Topical Section Header}
This is for topical sections
\ssection{Summary Section Header}
I'd like to replace this topical header with a similar tikz bar which has 'Summary' in the black node
\end{document}
答案1
通过反复试验,我解决了这个问题,如下。
基于 titlebar@@ 定义了一个新命令 stitlebar@@
\newcommand\stitlebar@@{%ssections \tikz[baseline,trim left=3.1cm,trim right=3.15cm] { \fill [black!15] (2.5cm,-1ex) 矩形 (\textwidth+3.6cm,2.5ex); \node [fill=black!15!white, 锚点= base east, 圆角矩形, 最小高度=3.5ex] 位于 (2.8cm,0.13) {}; \node [fill=black!100!white, 锚点= base east, 圆角矩形, 最小高度=3.5ex] 位于 (14.0cm,0.03) { \color{white}{Summary}}; }}
定义了两个新命令,summary和ssection:
\newcommand\summary{\stitlebar@@} \newcommand{\ssection}1{\section*{\summary#1}}
向 MWE 添加了部分内容(现已编辑以包含此版本)
结果: