![將框新增至標記部分](https://rvso.com/image/287000/%E5%B0%87%E6%A1%86%E6%96%B0%E5%A2%9E%E8%87%B3%E6%A8%99%E8%A8%98%E9%83%A8%E5%88%86.png)
我想在教科書的重複部分添加一個框,其中提供問題討論。是否可以透過在序言中加入「tex style setting」指令來做到這一點?我正在使用回憶錄課程。
(我需要它是因為我透過 Scrivener 和 Multimarkdown 在 LaTeX 文件中產生主要內容,而不是手動編寫。)
我用過 tex這裡產生一些漂亮的章節標題。我想做的是將類似的樣式應用於本章末尾的兩個部分(摘要和討論),但因為這些不是部分,因此我希望它們的標題沒有部分編號。
這是關鍵文字:
\newcommand\titlebar{%
\tikz[baseline,trim left=3.1cm,trim right=3cm] {
\fill [black!10] (2.5cm,-1ex) rectangle (\textwidth+3.8cm,2.5ex);
\node [
fill=cyan!60!white,
fill=black!90!white,
anchor= base east,
rounded rectangle,
minimum height=3.75ex] at (2.9cm,0) {
\textbf{\arabic{chapter}.\thesection.}
\color{white}\textbf{T\thesection}
};
}%
}
\titleformat{\section}{\large}{\titlebar}{0.1cm}{}
\renewcommand*{\thesection}{\arabic{section}}
這對我的章節標題(包括章節號)套用了很好的樣式。現在我想對出現在本章末尾的兩個部分(摘要和討論)套用類似的樣式。但我希望這兩個部分沒有部分編號。
答案1
我想說最好為關鍵部分定義一個新的宏,例如
\newcommand{\dsection}[1]{\section*{\titlebar*#1}}
帶有簡化(加星號)版本\titlebar
(請參閱下面的完整程式碼)。
\documentclass{memoir}
\usepackage{titlesec,letltxmacro}
\usepackage{lipsum}
\usepackage{tikz}\usetikzlibrary{shapes.misc}
\makeatletter
\newcommand\titlebar@@{%
\tikz[baseline,trim left=3.1cm,trim right=3cm] {
\fill [cyan!25] (2.5cm,-1ex) rectangle (\textwidth+3.1cm,2.5ex);
}}
\newcommand\titlebar@{%
\tikz[baseline,trim left=3.1cm,trim right=3cm] {
\fill [cyan!25] (2.5cm,-1ex) rectangle (\textwidth+3.1cm,2.5ex);
\node [
fill=cyan!60!white,
anchor= base east,
rounded rectangle,
minimum height=3.5ex] at (3cm,0) {
\textbf{\arabic{chapter}.\thesection.}
};
}}
\newcommand\titlebar{\@ifstar\titlebar@@\titlebar@}
\titleformat{\section}{\large}{\titlebar}{0.1cm}{}
\renewcommand*{\thesection}{\arabic{section}}
\LetLtxMacro{\LtxSection}{\section}
\newcommand{\dsection}[1]{\LtxSection*{\titlebar*#1}}
\renewcommand{\section}[2][]{%
\def\secname{#2}
\ifx\somename\secname
\LtxSection*{\titlebar*#2}
\else
\LtxSection[#1]{#2}
\fi}
\def\somename{Summary}
\makeatother
\begin{document}
\chapter{First Chapter}
\section{Section name}
\lipsum[2]
\dsection{Some other Chapter}
\lipsum[2]
\section{Summary}
\lipsum[2]
\end{document}
筆記:根據要求,該\desction
格式將自動套用於名為「摘要」的每個部分。
附錄
要使章節標題變為粗體,您只需更改該行
\titleformat{\section}{\large}{\titlebar}{0.1cm}{}
到
\titleformat{\section}{\large\bfseries}{\titlebar}{0.1cm}{}