다양한 환경에서 배경색 변경

다양한 환경에서 배경색 변경

긴 .tex 문서가 있는데 이미 오타가 있는지 확인한 부분의 배경색을 연한 녹색으로 변경하고 싶습니다. 다음과 같이 사용할 수 있는 쉬운 명령을 찾고 있습니다.

\HIGHLIGHT{

<here I want to put a part of my tex file that contains different environments like theorems, figures...>

}

그러나 \hl{}명령은 다른 환경을 포함할 수 없으며 다음 예는 작동하지 않습니다.

\documentclass[10pt]{article}         
\usepackage[english]{babel}
\usepackage{amssymb,amsmath,amsthm,amsfonts}
\usepackage{xcolor,soul}

\newtheorem{theorem}{Theorem}
\begin{document}
\section{Introduction}
\hl{
    \begin{theorem}
    A theorem.
    \end{theorem}
}
\end{document}

여기서 사용할 수 있는 명령이 있습니까(조판은 변경되지 않고 색상만 변경됨)?

답변1

질문에 대한 내 의견 중 하나에서 제안한 것처럼 기본적으로 동일한 두 가지 환경을 갖는 매크로를 사용합니다. 하나는 을 사용하고 tcolorbox다른 하나는 . 정리가 아직 확인되지 않은 경우 나중에 이를 사용하고 편집 하거나 의 정의에서 해당 명령문을 제거하십시오 .\newtcbtheoremcheckedstyleuncheckedstyle\begin{uctheorem}...\end{uctheorem}\begin{theorem}...\end{theorem}colback={green!50!white}uncheckedstyle

결국 내 생각에는 a가 가장 좋은 방법이겠지만, 그건 물론 취향의 문제 다 search-and-replace.uctheoremtheorem

또 다른 옵션은 옵션의 로컬 지정을 허용하는 '실제' 환경을 사용하는 것인데 tcolorbox, 이는 환경에서는 불가능합니다 tcbtheorem.

\documentclass[10pt]{article}         
\usepackage[english]{babel}
\usepackage{amssymb,amsmath,amsthm,amsfonts}
\usepackage{xcolor}
\usepackage[most]{tcolorbox}

\tcbset{%
  checkedstyle/.style={breakable,enhanced, sharp corners,colback={yellow!50!white}},
  uncheckedstyle/.style={checkedstyle,colback={green!50!white}}
}

\newtcbtheorem{theorem}{Theorem}{checkedstyle}{theo}

\newtcbtheorem{uctheorem}{Theorem}{uncheckedstyle}{theo}




\begin{document}
\section{Introduction}
\begin{theorem}{My theorem}{foo}
  A theorem.
\end{theorem}

\begin{uctheorem}{My other theorem}{foobar}
  An unchecked theorem
\end{uctheorem}

\end{document}

여기에 이미지 설명을 입력하세요

답변2

LaTeX 문서의 임의 부분을 강조 표시하는 사용 사례에 잘 작동하는 대안으로 흥미로운 접근 방식은 colorafterpage 패키지를 사용하여 페이지 배경을 부분적으로 색칠하는 것입니다(기반).https://tex.stackexchange.com/a/237427/223749). 이는 콘텐츠를 전혀 변경할 필요가 없으며 형식도 영향을 받지 않는다는 장점이 있습니다. 강조 표시는 전체 줄만 포함하고 왼쪽 및 오른쪽 여백도 포함하지만 사용 사례에서는 문제가 되지 않는 것 같습니다. 또한 강조 표시 환경 내부에 부동 소수점이 있고 그 외부로 부동 소수점이 있는 경우 강조 표시되지 않습니다.

정리, 그림 및 페이지 나누기를 포함한 MWE:

\documentclass{article}

\usepackage{mwe}

\usepackage{amssymb,amsmath,amsthm,amsfonts}
\newtheorem{theorem}{Theorem}

\usepackage{color}
\definecolor{lightgreen}{rgb}{0.56, 0.93, 0.56}

\usepackage{afterpage}

\makeatletter
% Macro \changepagecolor has the same syntax as \pagecolor or \color
% with an optional argument and a mandatory argument.
\newcommand*{\changepagecolor}{%
  \@ifnextchar[\@changepagecolor@i\@changepagecolor@ii
}
% Case: \changepagecolor[...]{...}
\def\@changepagecolor@i[#1]#2{%
  \@changepagecolor@do{[{#1}]{#2}}%
}
% Case: \changepagecolor{...}
\newcommand*{\@changepagecolor@ii}[1]{%
  \@changepagecolor@do{{#1}}%
}
\newcommand*{\@changepagecolor@do}[1]{%
  % Fill the remaining space with a colored rule
  \begingroup
    \offinterlineskip
    \hbox to 0pt{%
      \kern-\paperwidth
      \vtop to 0pt{%
        \color#1%
        \hrule width 2\paperwidth height \paperheight
        \vss
      }%
      \hss
    }%
  \endgroup
  % Set page color for the next page
  \afterpage{\pagecolor#1}%
}
\makeatother

\newenvironment{highlight}%
  {\changepagecolor{lightgreen}}%
  {\changepagecolor{white}}


\begin{document}
\blindtext
\blindtext
\blindtext
\blindtext

\begin{highlight}
\blindtext

\begin{theorem}
    a theorem.
\end{theorem}

\begin{figure}[!h]
    \includegraphics[width=.4\textwidth]{example-image-a}\hfill
    \includegraphics[width=.4\textwidth]{example-image-b}
    \caption{This is a figure caption within the custom highlight environment}
\end{figure}
\end{highlight}

\blindtext
    
\end{document}

결과:

여기에 이미지 설명을 입력하세요

관련 정보