1

Here's my current preamble.tex

\documentclass{report}

% basics \usepackage[utf8]{inputenc} \usepackage[T1]{fontenc} \usepackage{sidenotes} \usepackage{textcomp} \usepackage{url} \usepackage{hyperref} \hypersetup{ colorlinks, linkcolor={black}, citecolor={black}, urlcolor={blue!80!black} } \usepackage{graphicx} \usepackage{lipsum} \usepackage{float} \usepackage{booktabs} \usepackage[shortlabels]{enumitem} \usepackage{emptypage} \usepackage{subcaption} \usepackage{multicol} \usepackage[usenames,dvipsnames]{xcolor} \usepackage{amsmath, amsfonts, mathtools, amsthm, amssymb} \usepackage{mathrsfs} \usepackage{cancel} \usepackage{bm} \usepackage{systeme} \usepackage{stmaryrd}

% theorems \usepackage{thmtools} \usepackage[framemethod=TikZ]{mdframed} \mdfsetup{skipabove=1em,skipbelow=0em, innertopmargin=5pt, innerbottommargin=6pt}

\theoremstyle{definition}

\makeatletter

@ifclasswith{report}{nocolor}{ \declaretheoremstyle[headfont=\bfseries\sffamily, bodyfont=\normalfont, mdframed={ nobreak } ]{thmgreenbox} \declaretheoremstyle[headfont=\bfseries\sffamily, bodyfont=\normalfont, mdframed={ nobreak } ]{thmredbox} \declaretheoremstyle[headfont=\bfseries\sffamily, bodyfont=\normalfont]{thmbluebox} \declaretheoremstyle[headfont=\bfseries\sffamily, bodyfont=\normalfont]{thmblueline} \declaretheoremstyle[headfont=\bfseries\sffamily, bodyfont=\normalfont, numbered=no, mdframed={ rightline=false, topline=false, bottomline=false, }, qed=\qedsymbol ]{thmproofbox} \declaretheoremstyle[headfont=\bfseries\sffamily, bodyfont=\normalfont, numbered=no, mdframed={ nobreak, rightline=false, topline=false, bottomline=false } ]{thmexplanationbox} \AtEndEnvironment{eg}{\null\hfill$\diamond$}% }{ \declaretheoremstyle[ headfont=\bfseries\sffamily\color{ForestGreen!70!black}, bodyfont=\normalfont, mdframed={ linewidth=2pt, rightline=false, topline=false, bottomline=false, linecolor=ForestGreen, backgroundcolor=ForestGreen!5, } ]{thmgreenbox}

\declaretheoremstyle[ headfont=\bfseries\sffamily\color{NavyBlue!70!black}, bodyfont=\normalfont, mdframed={ linewidth=2pt, rightline=false, topline=false, bottomline=false, linecolor=NavyBlue, backgroundcolor=NavyBlue!5, } ]{thmbluebox}

\declaretheoremstyle[ headfont=\bfseries\sffamily\color{NavyBlue!70!black}, bodyfont=\normalfont, mdframed={ linewidth=2pt, rightline=false, topline=false, bottomline=false, linecolor=NavyBlue } ]{thmblueline}

\declaretheoremstyle[ headfont=\bfseries\sffamily\color{RawSienna!70!black}, bodyfont=\normalfont, mdframed={ linewidth=2pt, rightline=false, topline=false, bottomline=false, linecolor=RawSienna, backgroundcolor=RawSienna!5, } ]{thmredbox}

\declaretheoremstyle[ headfont=\bfseries\sffamily\color{RawSienna!70!black}, bodyfont=\normalfont, numbered=no, mdframed={ linewidth=2pt, rightline=false, topline=false, bottomline=false, linecolor=RawSienna, backgroundcolor=RawSienna!1, }, qed=\color{RawSienna!70!black}\qedsymbol ]{thmproofbox}

\declaretheoremstyle[ headfont=\bfseries\sffamily\color{NavyBlue!70!black}, bodyfont=\normalfont, numbered=no, mdframed={ linewidth=2pt, rightline=false, topline=false, bottomline=false, linecolor=NavyBlue, backgroundcolor=NavyBlue!1, }, ]{thmexplanationbox} }

@ifclasswith{report}{nocolor}{ \declaretheorem[style=thmproofbox, name=Proof]{replacementproof} \declaretheorem[style=thmexplanationbox, name=Proof]{explanation} \renewenvironment{proof}[1][\proofname]{\begin{replacementproof}}{\end{replacementproof}} }{ \declaretheorem[style=thmproofbox, name=Proof]{replacementproof} \renewenvironment{proof}[1][\proofname]{\vspace{-10pt}\begin{replacementproof}}{\end{replacementproof}}

\declaretheorem[style=thmexplanationbox, name=Proof]{tmpexplanation} \newenvironment{explanation}[1][]{\vspace{-10pt}\begin{tmpexplanation}}{\end{tmpexplanation}} }

\makeatother

\declaretheorem[style=thmgreenbox, name=Definition]{definition} \declaretheorem[style=thmredbox, name=Proposition]{prop} \declaretheorem[style=thmredbox, name=Theorem]{theorem} \declaretheorem[style=thmredbox, name=Lemma]{lemma} \declaretheorem[style=thmredbox, numbered=no, name=Corollary]{corollary} \declaretheorem[style=thmblueline, numbered=no, name=Remark]{remark} \declaretheorem[style=thmblueline, numbered=no, name=Example]{example} \declaretheorem[style=thmblueline, numbered=no, name=Solution]{solution}

\newtheorem{exc}{Exercise} \newtheorem{notation}{Notation} \newtheorem{note}{Note} \newtheorem{previouslyseen}{As previously seen} \newtheorem{problem}{Problem} \newtheorem{observe}{Observe} \newtheorem{property}{Property} \newtheorem*{intuition}{Intuition}

\begin{document} \begin{definition} \begin{table}[H] \label{tbl:degrees_into_radians} \begin{tabular}{|c|c|c|c|} \hline $1$, $2$, $3$, $4$ \hline \end{tabular} \caption{Some Cool Label} \end{table} \end{definition} \end{document}

How can I get the label color to change to the color of the border from the environment? In this example, how would I change the label color to be green like the definition environment?

FHZ
  • 3,939

2 Answers2

1

Following this answer, a possible solution is presented in the following MWE based on caption:

\documentclass{article}
\usepackage{caption}
\usepackage{xcolor}

\captionsetup[table]{labelfont={color=green!50!black},font={color=green}} \captionsetup[figure]{labelfont={color=red},font={color=red!50}}

\begin{document}

\begin{table}[htp] \caption{A table} \end{table}

\begin{figure}[htp] \caption{A figure} \end{figure}

\end{document}

enter image description here

Personal opinion: I always see green as too bright and normally difficult to look at, I prefer green!50!black.


Edit -- Improved answer

Let's quote caption's manual page 4.

It’s good to know that \captionsetup has an effect on the current environment only. So if you want to change settings for the current figure or table only, just place the \captionsetup command inside the figure or table right before the \caption command.

So the idea is to define a specific \captionsetup inside each \newenvironment. In the MWE those \newenvironment are mySpecialEnvironment.

I also used this answer to keep all captions on the same page.

\documentclass{article}
\usepackage{xcolor}
\usepackage{caption}
\captionsetup[table]{labelfont={color=green!50!black},font={color=green}}
\captionsetup[figure]{labelfont={color=red},font={color=red!50}}

\newenvironment{mySpecialEnvironment} {\captionsetup[table]{labelfont={color=purple!75!black},font={color=purple}} \captionsetup[figure]{labelfont={color=orange!75!black},font={color=orange}} } {}

\setcounter{topnumber}{8} \setcounter{bottomnumber}{8} \setcounter{totalnumber}{8} \begin{document} \begin{table}[!ht] \caption{A table} \end{table} \begin{figure}[!ht] \caption{A figure} \end{figure} \begin{mySpecialEnvironment} \begin{table}[!ht] \caption{A table} \end{table} \begin{figure}[!ht] \caption{A figure} \end{figure} \end{mySpecialEnvironment} \begin{figure}[!ht] \caption{A figure} \end{figure} \begin{table}[!ht] \caption{A table} \end{table} \begin{figure}[!ht] \caption{A figure} \end{figure} \begin{mySpecialEnvironment} \begin{table}[!ht] \caption{A table} \end{table} \begin{figure}[!ht] \caption{A figure} \end{figure} \end{mySpecialEnvironment} \begin{figure}[!ht] \caption{A figure} \end{figure} \end{document}

enter image description here

Note: Please, notice there might be other answers using \makeatletter and \makeatother like your \declaretheorems, but here I didn't look for these options.

FHZ
  • 3,939
  • Thanks! But, how would I add it to the environment? For example, I would like to make all of the captions green when inside the definition environment, but all the captions red when the theorem environment. – SingularisArt Apr 09 '22 at 02:20
  • 1
    I need to investigate further. Despite my answer does answers the basic question, it does not answer your real question. It is something like this: "How do I want to define an environment that defines the color of each caption inside it but not outside it". – FHZ Apr 09 '22 at 02:46
  • 1
    @SingularisArt, please, check if the edit improved answer satisfy your requirements. – FHZ Apr 09 '22 at 03:29
  • 1
    Yes. Thank you! – SingularisArt Apr 09 '22 at 04:07
1

Here's my final answer. Thanks a ton to @FHZ

This answer uses

\AtBeginEnvironment{<envname>}{
  \captionsetup{...}
}

to define how all captions will be presented inside each environment.

\documentclass{report}

% basics \usepackage[utf8]{inputenc} \usepackage[T1]{fontenc} \usepackage{sidenotes} \usepackage{textcomp} \usepackage{url} \usepackage{hyperref} \hypersetup{ colorlinks, linkcolor={black}, citecolor={black}, urlcolor={blue!80!black} } \usepackage{graphicx} \usepackage{lipsum} \usepackage{float} \usepackage{booktabs} \usepackage[shortlabels]{enumitem} \usepackage{emptypage} \usepackage{subcaption} \usepackage{multicol} \usepackage[usenames,dvipsnames]{xcolor} \usepackage{amsmath, amsfonts, mathtools, amsthm, amssymb} \usepackage{mathrsfs} \usepackage{cancel} \usepackage{bm} \usepackage{systeme} \usepackage{stmaryrd}

\usepackage{thmtools} \usepackage[framemethod=TikZ]{mdframed} \mdfsetup{skipabove=1em,skipbelow=0em, innertopmargin=5pt, innerbottommargin=6pt}

\theoremstyle{definition}

\colorlet{thmgreencolor}{ForestGreen!70!black} \colorlet{thmredcolor}{RawSienna!70!black} \colorlet{thmbluecolor}{NavyBlue!70!black} \colorlet{thmblueline}{NavyBlue!70!black} \colorlet{thmproofbox}{RawSienna!70!black} \colorlet{thmexplanationbox}{NavyBlue!70!black}

\makeatletter

@ifclasswith{report}{nocolor}{ \declaretheoremstyle[headfont=\bfseries\sffamily, bodyfont=\normalfont, mdframed={ nobreak } ]{thmgreenbox} \declaretheoremstyle[headfont=\bfseries\sffamily, bodyfont=\normalfont, mdframed={ nobreak } ]{thmredbox} \declaretheoremstyle[headfont=\bfseries\sffamily, bodyfont=\normalfont]{thmbluebox} \declaretheoremstyle[headfont=\bfseries\sffamily, bodyfont=\normalfont]{thmblueline} \declaretheoremstyle[headfont=\bfseries\sffamily, bodyfont=\normalfont, numbered=no, mdframed={ rightline=false, topline=false, bottomline=false, }, qed=\qedsymbol ]{thmproofbox} \declaretheoremstyle[headfont=\bfseries\sffamily, bodyfont=\normalfont, numbered=no, mdframed={ nobreak, rightline=false, topline=false, bottomline=false } ]{thmexplanationbox} \AtEndEnvironment{eg}{\null\hfill$\diamond$}% }{ \declaretheoremstyle[ headfont=\bfseries\sffamily\color{thmgreencolor}, bodyfont=\normalfont, mdframed={ linewidth=2pt, rightline=false, topline=false, bottomline=false, linecolor=ForestGreen, backgroundcolor=ForestGreen!5, } ]{thmgreenbox}

\declaretheoremstyle[ headfont=\bfseries\sffamily\color{thmredcolor}, bodyfont=\normalfont, mdframed={ linewidth=2pt, rightline=false, topline=false, bottomline=false, linecolor=RawSienna, backgroundcolor=RawSienna!5, } ]{thmredbox}

\declaretheoremstyle[ headfont=\bfseries\sffamily\color{thmbluecolor}, bodyfont=\normalfont, mdframed={ linewidth=2pt, rightline=false, topline=false, bottomline=false, linecolor=NavyBlue, backgroundcolor=NavyBlue!5, } ]{thmbluebox}

\declaretheoremstyle[ headfont=\bfseries\sffamily\color{thmblueline}, bodyfont=\normalfont, mdframed={ linewidth=2pt, rightline=false, topline=false, bottomline=false, linecolor=NavyBlue } ]{thmblueline}

\declaretheoremstyle[ headfont=\bfseries\sffamily\color{thmproofbox}, bodyfont=\normalfont, numbered=no, mdframed={ linewidth=2pt, rightline=false, topline=false, bottomline=false, linecolor=RawSienna, backgroundcolor=RawSienna!1, }, qed=\color{RawSienna!70!black}\qedsymbol ]{thmproofbox}

\declaretheoremstyle[ headfont=\bfseries\sffamily\color{thmexplanationbox}, bodyfont=\normalfont, numbered=no, mdframed={ linewidth=2pt, rightline=false, topline=false, bottomline=false, linecolor=NavyBlue, backgroundcolor=NavyBlue!1, }, ] {thmexplanationbox} }

@ifclasswith{report}{nocolor}{ \declaretheorem[style=thmproofbox, name=Proof]{replacementproof} \declaretheorem[style=thmexplanationbox, name=Proof]{explanation} \renewenvironment{proof}[1][\proofname]{\begin{replacementproof}}{\end{replacementproof}} }{ \declaretheorem[style=thmproofbox, name=Proof]{replacementproof} \renewenvironment{proof}[1][\proofname]{\vspace{-10pt}\begin{replacementproof}}{\end{replacementproof}}

\declaretheorem[style=thmexplanationbox, name=Proof]{tmpexplanation} \newenvironment{explanation}[1][]{\vspace{-10pt}\begin{tmpexplanation}}{\end{tmpexplanation}} }

\makeatother

\declaretheorem[style=thmgreenbox, name=Definition]{definition} \declaretheorem[style=thmredbox, name=Proposition]{prop} \declaretheorem[style=thmredbox, name=Theorem]{theorem} \declaretheorem[style=thmredbox, name=Lemma]{lemma} \declaretheorem[style=thmredbox, numbered=no, name=Corollary]{corollary} \declaretheorem[style=thmblueline, numbered=no, name=Remark]{remark} \declaretheorem[style=thmblueline, numbered=no, name=Example]{example} \declaretheorem[style=thmblueline, numbered=no, name=Solution]{solution}

\AtBeginEnvironment{definition}{ \captionsetup{labelfont={color=thmgreencolor}} } \AtBeginEnvironment{prop}{ \captionsetup{labelfont={color=thmredcolor}} } \AtBeginEnvironment{theorem}{ \captionsetup{labelfont={color=thmredcolor}} } \AtBeginEnvironment{lemma}{ \captionsetup{labelfont={color=thmredcolor}} } \AtBeginEnvironment{corollary}{ \captionsetup{labelfont={color=thmredcolor}} } \AtBeginEnvironment{remark}{ \captionsetup{labelfont={color=thmbluecolor}} } \AtBeginEnvironment{example}{ \captionsetup{labelfont={color=thmbluecolor}} } \AtBeginEnvironment{solution}{ \captionsetup{labelfont={color=thmbluecolor}} }

\newtheorem{exc}{Exercise} \newtheorem{notation}{Notation} \newtheorem{note}{Note} \newtheorem{previouslyseen}{As previously seen} \newtheorem{problem}{Problem} \newtheorem{observe}{Observe} \newtheorem{property}{Property} \newtheorem*{intuition}{Intuition}

\begin{document} \begin{definition}[Some Definition] \lipsum[1]

\begin{table}[H]
  \label{tbl:degrees_into_radians}
  \begin{tabular}{|c|c|c|c|}
    \hline
    $1$, $2$, $3$, $4$ \\
    \hline
  \end{tabular}
  \caption{Some Cool Label}
\end{table}

\end{definition}

\newpage

\begin{prop} \lipsum[1]

\begin{table}[H]
  \label{tbl:degrees_into_radians}
  \begin{tabular}{|c|c|c|c|}
    \hline
    $1$, $2$, $3$, $4$ \\
    \hline
  \end{tabular}
  \caption{Some Cool Label}
\end{table}

\end{prop}

\begin{theorem}[Some Theorem] \lipsum[1]

\begin{table}[H]
  \label{tbl:degrees_into_radians}
  \begin{tabular}{|c|c|c|c|}
    \hline
    $1$, $2$, $3$, $4$ \\
    \hline
  \end{tabular}
  \caption{Some Cool Label}
\end{table}

\end{theorem}

\begin{lemma} \lipsum[1]

\begin{table}[H]
  \label{tbl:degrees_into_radians}
  \begin{tabular}{|c|c|c|c|}
    \hline
    $1$, $2$, $3$, $4$ \\
    \hline
  \end{tabular}
  \caption{Some Cool Label}
\end{table}

\end{lemma}

\begin{corollary} \lipsum[1]

\begin{table}[H]
  \label{tbl:degrees_into_radians}
  \begin{tabular}{|c|c|c|c|}
    \hline
    $1$, $2$, $3$, $4$ \\
    \hline
  \end{tabular}
  \caption{Some Cool Label}
\end{table}

\end{corollary}

\newpage

\begin{remark} \lipsum[1]

\begin{table}[H]
  \label{tbl:degrees_into_radians}
  \begin{tabular}{|c|c|c|c|}
    \hline
    $1$, $2$, $3$, $4$ \\
    \hline
  \end{tabular}
  \caption{Some Cool Label}
\end{table}

\end{remark}

\begin{example} \lipsum[1]

\begin{table}[H]
  \label{tbl:degrees_into_radians}
  \begin{tabular}{|c|c|c|c|}
    \hline
    $1$, $2$, $3$, $4$ \\
    \hline
  \end{tabular}
  \caption{Some Cool Label}
\end{table}

\end{example}

\begin{solution} \lipsum[1]

\begin{table}[H]
  \label{tbl:degrees_into_radians}
  \begin{tabular}{|c|c|c|c|}
    \hline
    $1$, $2$, $3$, $4$ \\
    \hline
  \end{tabular}
  \caption{Some Cool Label}
\end{table}

\end{solution} \end{document}

enter image description here enter image description here enter image description here

FHZ
  • 3,939