警告和信息块的漂亮格式

警告和信息块的漂亮格式

我正在寻找漂亮的警告格式,以及其他一些信息或提示。

目前,我使用以下格式,但也许有人有更好的想法。

在此处输入图片描述

为了实现这一点,我使用了以下代码。

\documentclass[10pt,a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage[x11names,svgnames]{xcolor}
\usepackage{graphicx}
\usepackage{fourier-orns}
\usepackage[framemethod=tikz]{mdframed}
\usetikzlibrary{calc}

\makeatletter
% Default settings for warnings
    \newcommand{\warningSymbol}{\raisebox{0.8\depth}{\danger}}

    \definecolor{warningColorText}{named}{Red3}
    \definecolor{warningColorLine}{named}{Red3}
    \definecolor{warningColorBack}{named}{LemonChiffon1}
    \definecolor{warningColorBackSymbol}{named}{white}

% Inline mode
    \newcommand{\warning}[1]{%
        \textcolor{warningColorText}{\warningSymbol{}\,#1}%
    }

% Block mode
    \tikzset{
        warningsymbol/.style={
            rectangle,
            draw  = warningColorText,
            fill  = warningColorBackSymbol,
            scale = 1,
            overlay
        }
    }

    \mdfdefinestyle{warning}{%
        hidealllines      = true,
        leftline          = true,
        skipabove         = 12,
        skipbelow         = 12pt,
        innertopmargin    = 0.4em,%
        innerbottommargin = 0.4em,%
        innerrightmargin  = 0.7em,%
        rightmargin       = 0.85em,%
        innerleftmargin   = 1.1em,%
        leftmargin        = 0.85em,%
        middlelinewidth   = .2em,%
        linecolor         = warningColorLine,%
        backgroundcolor   = warningColorBack,%
        fontcolor         = warningColorText,%
        firstextra        = {
            \path let \p1=(P), \p2=(O) in ($(\x2,\y1-4)$)
            node[warningsymbol] {\warningSymbol};
        },%
        secondextra       = {
            \path let \p1=(P), \p2=(O) in ($(\x2,\y1-4)$) 
            node[warningsymbol] {\warningSymbol};
        },%
        middleextra       = {
            \path let \p1=(P), \p2=(O) in ($(\x2,\y1-4)$) 
            node[warningsymbol] {\warningSymbol};
        },%
        singleextra       = {
            \path let \p1=(P), \p2=(O) in ($(\x2,\y1-4)$) 
            node[warningsymbol] {\warningSymbol};
        },%
    }

    \newmdenv[style=warning]{@Warning}
    \newenvironment{Warning}{\let\warning\relax\begin{@Warning}}{\end{@Warning}}
\makeatother

\usepackage{lipsum}

\begin{document}

\warning{IMPORTANT !} \lipsum[1]

\begin{Warning}
     \lipsum[1]
\end{Warning}

\end{document}

答案1

你可以看看bclogo包。1允许您轻松创建自定义警告、信息等块:

\documentclass{article}

\usepackage{lipsum}
\usepackage[svgnames]{xcolor}
\usepackage[tikz]{bclogo}

\begin{document}
\begin{bclogo}[logo=\bcattention, noborder=true, barre=none]{Important!}
    \lipsum[1]
\end{bclogo}
\end{document}

在此处输入图片描述

\begin{bclogo}[logo=\bcattention, couleurBarre=red, noborder=true, 
               couleur=LightSalmon]{Important!}
    \lipsum[1]
\end{bclogo}

在此处输入图片描述

\begin{bclogo}[logo=\bcinfo, couleurBarre=orange, noborder=true, couleur=white]{Information}
    \lipsum[1]
\end{bclogo}
\end{document}

在此处输入图片描述


1我刚才提到该手册只有法语版。但由于它充满了例子,理解它应该不成问题。即使对于法语不通的人来说也是如此。

答案2

我正在对重要的部分使用类似的东西。

重要的

\documentclass{article}

\usepackage{xcolor,mdframed}

\newenvironment{important}[1][]{%
   \begin{mdframed}[%
      backgroundcolor={red!15}, hidealllines=true,
      skipabove=0.7\baselineskip, skipbelow=0.7\baselineskip,
      splitbottomskip=2pt, splittopskip=4pt, #1]%
   \makebox[0pt]{% ignore the withd of !
      \smash{% ignor the height of !
         \fontsize{32pt}{32pt}\selectfont% make the ! bigger
         \hspace*{-19pt}% move ! to the left
         \raisebox{-2pt}{% move ! up a little
            {\color{red!70!black}\sffamily\bfseries !}% type the bold red !
         }%
      }%
   }%
}{\end{mdframed}}

\usepackage{lipsum}

\begin{document}
\lipsum[1]
\begin{important}
   \lipsum[2]
\end{important}
\lipsum[1]
\end{document}

相关内容