在memoir
类文档中,我使用以下mdtheorem
定义在内提供标题mdframe
,其效果是为每个新的“{讨论}”引用提供一个增加的计数器。
\mdtheorem{discuss}{Discuss Topic}[chapter]
在文档正文中,我插入了begin{discuss}[\rightmark]
(在此页之后,http://glurl.co/dFD),这已经带给我一些启发。
它输出:Discuss Topic 1: 1 TITLE
。即,它重复讨论(主题/部分)编号并将标题置于大写字母中。我希望仅包含一次计数器并在正常情况下显示主题标题。
进一步与 Gonzalo 讨论,很明显,以下宏会产生两种不同类型的节(\section
和\osection
)标题,从而影响输出:
\usepackage{titlesec}
\usepackage{tikz}\usetikzlibrary{shapes.misc}
\makeatletter
\newcommand\titlebar@{%sections
\tikz[baseline,trim left=3.1cm,trim right=3.0cm] {
\fill [black!15] (2.5cm,-1ex) rectangle (\textwidth+3.1cm,2.5ex);
\node [
fill=black!100!white,
anchor= base east,
rounded rectangle,
minimum height=3.75ex] at (3cm,0.01) {
\color{white}\textbf{T\thesection}
};
}}
\newcommand\titlebar@@{%osections
\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!100!white,
anchor= base east,
rounded rectangle,
minimum height=3.75ex] at (3cm,0.15) {
};
}}
\newcommand\titlebar{\@ifstar\titlebar@@\titlebar@}
\titleformat{\section}{\large\bfseries}{\titlebar}{0.1cm}{}
\renewcommand*{\thesection}{\arabic{section}}
\newcommand{\osection}[1]{\section*{\titlebar*#1}}
\makeatother
答案1
您可以使用memoir
:\currenttitle
\documentclass{memoir}
\usepackage{mdframed}
\mdtheorem[style=mpdframe]{discuss}{Discuss Topic}[chapter]
\begin{document}
\chapter{Test chapter}
\section{Test section}
\label{sec:test}
\begin{discuss}[\currenttitle]
test text
\end{discuss}
\end{document}
上述代码的问题在于\currenttitle
存储最后的使用的节单元,可能不是一个节;在这种情况下,需要做一些额外的工作;\M@sect
使用一个补丁来存储当前部分在\currentsectionname
:
\documentclass{memoir}
\usepackage{mdframed}
\mdtheorem[style=mpdframe]{discuss}{Discuss Topic}[chapter]
\makeatletter
\let\currentsectiontitle\relax
\patchcmd{\M@sect}
{\ifheadnameref}
{\ifnum#2=1\relax
\gdef\currentsectiontitle{#9}
\fi
\ifheadnameref}
{}
{}
\makeatother
\begin{document}
\chapter{Test chapter}
\section{Test section}
\label{sec:test}
\begin{discuss}[\currentsectiontitle]
test text
\end{discuss}
\end{document}
mpdframe
问题中缺少风格的定义。
正如对这个问题的评论中提到的那样,因为这将用于每一个 discuss
环境,我认为最好使用\newmdtheoremenv
自定义定理样式来自动提供当前章节标题;类似这样的内容:
\documentclass{memoir}
\usepackage{amsthm}
\usepackage{mdframed}
\newtheoremstyle{mystyle}
{\topsep}
{\topsep}
{}
{}
{\bfseries}
{\newline}
{.5em}
{\thmname{#1}~\thmnumber{#2}: \currentsectiontitle}
\theoremstyle{mystyle}
\newmdtheoremenv{discuss}{Discuss Topic}[chapter]
\makeatletter
\let\currentsectiontitle\relax
\patchcmd{\M@sect}
{\ifheadnameref}
{\ifnum#2=1\relax
\gdef\currentsectiontitle{#9}
\fi
\ifheadnameref}
{}
{}
\makeatother
\begin{document}
\chapter{Test chapter}
\section{Test section one}
\subsection{Test subsection}
\label{sec:test}
\begin{discuss}
test text
\end{discuss}
\section{Test section two}
\subsection{Test subsection}
\label{sec:test}
\begin{discuss}
test text
\end{discuss}
\end{document}
编辑问题后更新
上述建议不起作用,因为titlesec
使用了包(对于该类来说,这可能不是一个好主意memoir
;请参阅关于 memoir 和 titlesec 不兼容)。在这种情况下,您可以使用:
\documentclass{memoir}
\usepackage{mdframed}
\usepackage[explicit]{titlesec}
\usepackage{tikz}
\usetikzlibrary{shapes.misc}
\mdtheorem[style=mpdframe]{discuss}{Discuss Topic}[chapter]
\makeatletter
\let\currentsectiontitle\relax
\newcommand\titlebar@{%sections
\tikz[baseline,trim left=3.1cm,trim right=3.0cm] {
\fill [black!15] (2.5cm,-1ex) rectangle (\textwidth+3.1cm,2.5ex);
\node [
fill=black!100!white,
anchor= base east,
rounded rectangle,
minimum height=3.75ex] at (3cm,0.01) {
\color{white}\textbf{T\thesection}
};
}}
\newcommand\titlebar@@{%osections
\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!100!white,
anchor= base east,
rounded rectangle,
minimum height=3.75ex] at (3cm,0.15) {
};
}}
\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}}
\makeatother
\begin{document}
\chapter{Test chapter}
\section{Test section}
\label{sec:test}
\begin{discuss}[\currentsectiontitle]
test text
\end{discuss}
\end{document}
或者通过新的定理样式进行自动包含:
\documentclass{memoir}
\usepackage{amsthm}
\usepackage{mdframed}
\usepackage[explicit]{titlesec}
\usepackage{tikz}
\usetikzlibrary{shapes.misc}
\newtheoremstyle{mystyle}
{\topsep}
{\topsep}
{}
{}
{\bfseries}
{\newline}
{.5em}
{\thmname{#1}~\thmnumber{#2}: \currentsectiontitle}
\theoremstyle{mystyle}
\newmdtheoremenv{discuss}{Discuss Topic}[chapter]
\makeatletter
\let\currentsectiontitle\relax
\newcommand\titlebar@{%sections
\tikz[baseline,trim left=3.1cm,trim right=3.0cm] {
\fill [black!15] (2.5cm,-1ex) rectangle (\textwidth+3.1cm,2.5ex);
\node [
fill=black!100!white,
anchor= base east,
rounded rectangle,
minimum height=3.75ex] at (3cm,0.01) {
\color{white}\textbf{T\thesection}
};
}}
\newcommand\titlebar@@{%osections
\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!100!white,
anchor= base east,
rounded rectangle,
minimum height=3.75ex] at (3cm,0.15) {
};
}}
\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}}
\makeatother
\begin{document}
\chapter{Test chapter}
\section{Test section one}
\subsection{Test subsection}
\begin{discuss}
test text
\end{discuss}
\section{Test section two}
\subsection{Test subsection}
\begin{discuss}
test text
\end{discuss}
\end{document}