在框架宏中填充颜色

在框架宏中填充颜色

我希望这个问题的答案很简单,所以我很抱歉我的无知。根据这里的帖子,我终于能够让框架按照我想要的方式显示。我制作了以下宏:

% make a box around text {framed}
\makeatletter
\renewenvironment{framed}{%
  \def\FrameCommand##1{\hskip\@totalleftmargin
  \fboxsep=\FrameSep\fbox{##1}
    \hskip-\linewidth \hskip-\@totalleftmargin \hskip\columnwidth}%
  \MakeFramed {\advance\hsize-\width
    \@totalleftmargin\z@ \linewidth\hsize
    \@setminipage}}%
  {\par\unskip\endMakeFramed}
\makeatother

我现在能够围绕我的警告和代码创建框架。以下是示例: 在此处输入图片描述

我的问题是:有没有一种简单的方法可以将警告框(注释)填充为黄色,将代码框填充为浅灰色?提前致谢。

答案1

这是带有徽标的tcolorbox版本。请注意,这样的盒子是不会破碎的!sidebyside

\documentclass{article}
\usepackage[svgnames,dvipsnames,x11names]{xcolor}
\usepackage[most]{tcolorbox}

\usepackage[tikz]{bclogo}

\newtcolorbox{framed}[1][]{
  colframe=lightgray,
  colback=yellow!40!white,
  enhanced jigsaw,
  sharp corners,
  lower separated=false,
  lefthand width=1cm,
  sidebyside gap=0.5cm,
  sidebyside,#1}

\begin{document}


\begin{framed}
  \bcbombe
  \tcblower
  To measure something use a ruler, a stop watch and scale!
\end{framed}

\begin{framed}[colback=blue!50!green]
  \bclampe
  \tcblower
  Brontosaurs are thin at one end, thick in the middle and thin again at the other end!
\end{framed}


\end{document}

在此处输入图片描述

答案2

非常接近您的代码片段,只需\fbox从包\fcolorbox中替换即可xcolor

\documentclass{article}

\usepackage{framed}
\usepackage{xcolor}
\usepackage{graphicx}

\definecolor{note}{rgb}{1 1 0.5}


\makeatletter
\renewenvironment{framed}{%
    \def\FrameCommand##1{\hskip\@totalleftmargin
        \fboxsep=\FrameSep\fcolorbox{black}{note}{##1}
        \hskip-\linewidth \hskip-\@totalleftmargin \hskip\columnwidth}%
    \MakeFramed {\advance\hsize-\width
        \@totalleftmargin\z@ \linewidth\hsize
        \@setminipage}}%
{\par\unskip\endMakeFramed}
\makeatother

\begin{document}

    \begin{framed}
        \includegraphics[width=1cm]{bc-crayon} \texttt{Libstdc++} is part...
    \end{framed}

    \definecolor{note}{rgb}{0.8 0.8 0.8}

    \begin{framed}
        \includegraphics[width=1cm]{bc-outil} \verb|mkdir -r bla|
    \end{framed}

\end{document}

在此处输入图片描述

答案3

我将shaded环境重新定义为framed具有框架,然后note根据ntheorem选项定义一个环境,framed如下所示shaded theorem

\documentclass[english]{article}
\usepackage[utf8]{inputenc} 
\usepackage{babel}
\usepackage{geometry}%
\usepackage[x11names]{xcolor}
\usepackage{fourier, erewhon} 
\usepackage{lipsum}
\usepackage{fontawesome} 
\usepackage{amsmath}
\usepackage[thmmarks, thref, amsmath, framed]{ntheorem}
\input{insbox} 
\newcommand\notesymbol{\relax}
\newtheoremstyle{note}%
  {\item[]\leavevmode\InsertBoxL{0}{\enspace\textcolor{Tomato1}{\LARGE\notesymbol\,}}[2]\hspace*{-\parindent}}%
  {\item[]\leavevmode\InsertBoxL{0}{\enspace\textcolor{Tomato1}{\LARGE\notesymbol\,}}[2]\hspace*{-\parindent}}%
\usepackage{framed}
\theoremstyle{note}
\colorlet{framecolor}{Grey0!80!RoyalBlue3!50!}
\colorlet{shadecolor}{Yellow1!45!}
\theoremframepreskip{6pt}
\theoremframepostskip{6pt}
\theoreminframepreskip{4pt}
\theoreminframepostskip{4pt}
\theoremheaderfont{\upshape}
\theorembodyfont{\normalfont}
\theoremseparator{}
\def\notesymbol{\faFileText}
\def\theoremframecommand{\setlength\fboxrule{1.5pt}\fcolorbox{framecolor}{shadecolor}}
\newshadedtheorem{note}{}

\begin{document}

\begin{note}%
Libstdc++ is part of the GCC sources.  You should first  unpack the GCC tarball and change to the \verb|gcc-5.2.0| directory.
\end{note}

\end{document}  

在此处输入图片描述

相关内容