麦利来

麦利来

我在想,在定理定义环境中所做的标记(带有extramarks)是否可以适应我创建的不同样式(定理、定义、备注)。我的想法是让定理、推论、介词 [···] 出现在深灰色框中;定义 [···] 出现在灰色框中,最后,备注出现在浅灰色框中。事实上,如果您查看代码,就会发现这就是我用 \newtheoremstyles 所做的。目前,除了备注为浅灰色外,它们都是深灰色(定义为“砷”)。我的问题是,如果我想让\theoremmarks标题文本出现在定理环境定义的特定颜色中,我必须如何修改代码。


笔记

在此处输入图片描述 对于那些还不明白我想做什么的人:如您所见,定理定义的环境的标签位于颜色框中。每个环境都有自己的颜色。我想知道是否有办法将带圆圈的数字(右上角,奇数页)放在链接颜色的颜色框中。


麦利来

styles.sty

\ProvidesPackage{styles}

% Packages
\usepackage[utf8]{inputenc}
\usepackage[catalan]{babel}
\usepackage[T1]{fontenc}
\usepackage{geometry}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{mathrsfs}
\usepackage{amsthm}
\usepackage{thmtools}
\usepackage[svgnames]{xcolor}
\usepackage{graphicx}
\usepackage{setspace}
\usepackage{enumitem}
\usepackage{float}
\usepackage{centernot}
\usepackage{titling}
\usepackage[explicit]{titlesec}
\usepackage{booktabs}
\usepackage{emptypage}

% Parameters
\geometry{a4paper, total={170mm,257mm}, left=19.1mm, right=19.1mm, top=25.4mm, bottom=25.4mm}

% Header
\usepackage{extramarks}
\usepackage{etoolbox}
\usepackage{fancyhdr}
\definecolor{arsenic}{rgb}{0.23, 0.27, 0.29}
\definecolor{lightsilver}{RGB}{248, 248, 248}
\definecolor{silver}{RGB}{245, 245, 245}
\definecolor{darksilver}{RGB}{230, 230, 230}
\definecolor{ultralight}{RGB}{253, 253, 253}

% Save standard definitions
\let\HeadRule\headrule
% Add color to standard definitions.
\renewcommand\headrule{\color{lightgray}\HeadRule}
\renewcommand{\headrulewidth}{0.1pt}


\fancypagestyle{nor}{% <===========================================
    \fancyhead[RE]{\textcolor{black}{\nouppercase{\leftmark}}}
    \fancyhead[LO]{\textcolor{black}{\nouppercase{\lastrightxmark}}}
    \fancyhead[CE,CO]{}
    \fancyhead[RO]{\textbf{\textcolor{arsenic}{{\botmarks\theoremmarks}}}}
    \fancyhead[LE]{\textcolor{black}{\textit{\lastleftxmark}}}
    \fancyfoot[RO, LE]{\fontsize{10pt}{10pt}\selectfont\thepage}
    \fancyfoot[CO, CE]{}
    \fancyheadoffset[LE,RO]{+0.025\textwidth}
    \fancyheadoffset[RE,LO]{+0.0\textwidth}
}
\fancypagestyle{toc}{% <===========================================
    \fancyhead[RE,LO,RO,LE]{}
    \fancyhead[CE,CO]{\textsc{Índex}}
    \fancyfoot[RO, LE]{\thepage}
    \fancyfoot[CO, CE]{}
    \fancyheadoffset[]{+0.025\textwidth}
}
\fancypagestyle{toenv}{% <===========================================
    \fancyhead[RE,LO,RO,LE]{}
    \fancyhead[CE,CO]{\textsc{Taula}}
    \fancyfoot[RO, LE]{\thepage}
    \fancyfoot[CO, CE]{}
    \fancyheadoffset[]{+0.025\textwidth}
}
\fancypagestyle{intr}{% <===========================================
    \fancyhead[RE,LO,RO,LE]{}
    \fancyhead[CE,CO]{\textsc{Introducció}}
    \fancyfoot[RO, LE]{\thepage}
    \fancyfoot[CO, CE]{}
    \fancyheadoffset[]{+0.025\textwidth}
}
% Pieter Van Oostrum - "In fancyhdr version 3, the initialisation was done when the first \pagestyle{fancy} (or one of its derived pagestyles) was given, including the initialisation of \chaptermark and \sectionmark"
\pagestyle{nor}
\renewcommand{\chaptermark}[1]{\markboth{#1}{}\extramarks{}{}}
\renewcommand{\sectionmark}[1]{\extramarks{\thesection}{#1}}
\renewcommand{\subsectionmark}[1]{\extramarks{\thesubsection}{#1}}

\newmarks\theoremmarks
\apptocmd\@begintheorem
   {\message{\@currenvir: #2}\marks\theoremmarks{#2}}
   {\message{patch \string\@begintheorem}}{\FAIL\@begintheorem}



% Definicions, teoremes, lemes...

\makeatletter
\newtheoremstyle{theorem}%
{}{}{\itshape}{-.325em}{\bfseries}{}{.5em} 
{
    \setlength{\fboxsep}{1pt}\colorbox{darksilver}{\color{arsenic}\thmname{#1}%
    \thmnumber{\@ifnotempty{#1}{ }\@upn{#2}}%
    \thmnote{ {(\textsc{\the\thm@notefont#3})}}.}%
}
\makeatother


\theoremstyle{theorem}
\newtheorem{theorem}{Teorema}[section]
\newtheorem{prop}[theorem]{Proposició}
\newtheorem{lemma}[theorem]{Lema}
\newtheorem{corollary}[theorem]{Corol·lari}
\newtheorem{property}[theorem]{Propietat}
\newtheorem{conjecture}[theorem]{Conjectura}
\newtheorem{process}[theorem]{Procés}
\newtheorem{exercise}{Exercici}[section]

\makeatletter
\newtheoremstyle{definition}%
{}{}{}{-.325em}{\bfseries}{}{.5em} 
{
    \setlength{\fboxsep}{1pt}\colorbox{silver}{\color{arsenic}\thmname{#1}%
    \thmnumber{\@ifnotempty{#1}{ }\@upn{#2}}%
    \thmnote{ {(\textsc{\the\thm@notefont#3})}}.}%
}

\theoremstyle{definition}
\newtheorem{definition}[theorem]{Definició}
\newtheorem{exmp}[theorem]{Exemple}
\newtheorem{notation}[theorem]{Notació}

\makeatletter
\newtheoremstyle{remark}%
{}{}{}{-.325em}{\bfseries}{}{.5em} 
{
    \setlength{\fboxsep}{1pt}\colorbox{lightsilver}{\color{arsenic}\thmname{#1}%
    \thmnumber{\@ifnotempty{#1}{ }\@upn{#2}}%
    \thmnote{ {(\textsc{\the\thm@notefont#3})}}.}%
}
\makeatother

\theoremstyle{remark}
\newtheorem{remark}[theorem]{Observació}

% Renew commands, canvis de format
\renewcommand\qedsymbol{\color{gray}$\blacksquare$}

% TITLE FORMAT
\usepackage[explicit]{titlesec}
\usepackage{array}
\titleformat{\chapter}[display]{\itshape\Large\centering\color{black}}{\centering\Huge\bfseries\sc\romannumeral\thechapter}{1ex}{\titleline{\color{lightgray}\titlerule[0.1pt]\vspace{1ex}}#1}
\titleformat{name=\chapter,numberless}[display]{\itshape\Large\centering\color{black}}{}{1ex}{#1}[\titleline{\color{lightgray}\titlerule[0.1pt]\vspace{1ex}}]
\titlespacing*{\chapter}{0pt}{-50pt}{40pt}
\titleformat{\section}[frame]
{\color{lightgray}\large\normalfont\mdseries\scshape\centering}{\filcenter\small \quad\textcolor{black}{\textit{\thesection}}\quad}
{1ex}{\color{black}\Large\bfseries\filcenter#1}[]
\titleformat{\subsection}[hang]{\normalfont\mdseries\scshape\centering}{\color{lightgray}\textit{\thesubsection}}{2ex}{\colorbox{ultralight}{\begin{tabular}[t]{@{\color{lightgray}\vrule width 0.1pt\hspace{2ex}}p{0.85\textwidth}}\raggedright#1\end{tabular}}}
\numberwithin{equation}{section}

main.tex

\documentclass[a4paper,12pt,twoside]{book}
\usepackage{styles}
\usepackage{kantlipsum}
\usepackage{hyperref}

\begin{document}
\chapter{Chapter One}
\section{Section A}
\kant[1]
\begin{remark}
Note that remark ("observació") labels are in a light gray box, whereas in a theorem environment they are dark gray colored.
\end{remark}
\begin{definition}
Definitions ("definició") are of a different gray, too.
\end{definition}
\begin{theorem}\label{th}
Test theorem. On the odd pages, code is programmed to display the number of the last math-defined environment in the page. So, I would want \verb|\theoremmarks| header text to appear in the particular color the theorem environment is defined as.
\end{theorem}
\kant[2-7]
\subsection{LOOK AT THE TOP RIGHT CORNER!}
We have to modify code in order to achieve what I mentioned in \ref{th}.
\end{document}

答案1

修正答案

(1)定义一个新命令来保存颜色名称,\newcommand\thhdrcolor{Fuchsia}比如说。

(2) 在每个 theoremstyle 定义中全局重新定义它。关键部分是重置需要在 th/def/remark 环境之外可见,因此必须是全局的,而不是局部的(我使用了\xdef)。

我使用了红色、绿色、蓝色,只是为了夸张:\xdef\thhdrcolor{red}对于定理:

\newtheoremstyle{theorem}%
{}{}{\itshape}{-.325em}{\bfseries}{}{.5em} 
{
\xdef\thhdrcolor{red}%******************
    \setlength{\fboxsep}{1pt}\colorbox{darksilver}{\color{\thhdrcolor}\thmname{#1}%
    \thmnumber{\@ifnotempty{#1}{ }\@upn{#2}}%
    \thmnote{ {(\textsc{\the\thm@notefont#3})}}.}%
}

另外两个也类似。

三个全部

(3)将 colourname 命令放在标头定义中:

    \fancyhead[RO]{\textbf{\textcolor{\thhdrcolor}{x{\botmarks\theoremmarks}x}}}%******************

结果:

添加足够多的页面并加上足够多的注释和定义即可得到:

红色的

绿色的

蓝色的

x只是我的标记。


原始答案

arsenic我编辑了的定义\definecolor{arsenic}{RGB}{250, 120, 0},以便更清楚地看到发生了什么。

如果我正确理解了你的问题,代码已经可以运行了。

颜色体现在标题中:

右上角

并且也符合定理:

定理颜色

那么,以此为基础,如果我误解了,您的要求是什么?

答案2

在得到@Cicada 的广泛回应和进行一些研究之后,我(不久前)使用 解决了这个问题extramarks,我已经用它来跟踪我的定理定义的环境。

\makeatletter
\newtheoremstyle{theorem}{}{}{\itshape}{}{\bfseries}{}{.5em}%
{%
\xdef\boxcolor{darksilver}%
\xdef\fontcolor{arsenic}%
\setlength{\fboxsep}{0pt}\colorbox{\boxcolor}{\color{\fontcolor}\thmname{#1}%
\thmnumber{\@ifnotempty{#1}{ }\@upn{#2}}%
\thmnote{ {(\textsc{\the\thm@notefont#3})}}.}%
}
\makeatother
%%%%%%%%%%%%%% MORE CODE... %%%%%%%%%%%%%%%%%
% Color de la capsa
\makeatletter
\newmarks\colorboxmark
\apptocmd\@begintheorem
{\message{\@currenvir: #2}\marks\colorboxmark{\boxcolor}}
{\message{patch \string\@begintheorem}}{\FAIL\@begintheorem}
\makeatother
% Color de la lletra
\makeatletter
\newmarks\colorthmmark
\apptocmd\@begintheorem
{\message{\@currenvir: #2}\marks\colorthmmark{\fontcolor}}
{\message{patch \string\@begintheorem}}{\FAIL\@begintheorem}
\makeatother
%%%%%%%%%%%%%% MORE CODE... %%%%%%%%%%%%%%%%%
\fancyhead[RO]{\setlength{\fboxsep}{0pt}\colorbox{\botmarks\colorboxmark}{\color{\botmarks\colorthmmark}\textbf{\botmarks\theoremmarks}}}

我尽可能简短地讲了,因为这个帖子并没有引起我想象中的关注。如果有人想了解更多详情,请随时联系我们。

相关内容