ラベル付きセクションにボックスを追加する

ラベル付きセクションにボックスを追加する

教科書の繰り返しセクションに、質問のディスカッションを提供するボックスを追加したいと考えています。プリアンブルに「Tex スタイル設定」コマンドを追加することで、これを実現できますか? 私は memoir クラスを使用しています。

(LaTeX ファイルの主なコンテンツを手動で記述するのではなく、Scrivener と Multimarkdown を使用して生成しているため、これが必要です。)

私はTexから使用しましたここ素敵なセクション見出しを生成します。私がやりたいのは、章の終わりにある 2 つのセクション (要約と考察) に同様のスタイルを適用することですが、これらはセクションではないので、セクション番号なしの見出しが必要です。

これは重要なテキストです:

\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}}

これにより、セクション番号を含むセクション見出しに適切なスタイルが適用されます。次に、章の最後に表示される 2 つのセクション (概要と考察) に同様のスタイルを適用します。ただし、これら 2 つのセクションにはセクション番号を付けないようにします。

答え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}{}

関連情報