乳胶内的彩色盒子

乳胶内的彩色盒子

我想制作不同颜色的彩色盒子,但我不明白 mybox{} 命令的功能。我附上了一个在此处输入图片描述可能对您有帮助的示例。

我写代码

\documentclass[a4paper]{report}

\usepackage[greek]{babel}
\usepackage[iso-8859-7]{inputenc}
\usepackage{xcolor}
\usepackage{blindtext}
\usepackage{tikz,tkz-tab,amsmath}

\begin{document}

\newcommand{\mybox}[1]{%
         \begin{center}%
            \begin{tikzpicture}%
                \node[rectangle, draw=green, top color=green!10, bottom color=green!90, rounded corners=5pt, inner xsep=5pt, inner ysep=6pt, outer ysep=10pt]{
                \begin{minipage}{1.05\linewidth}#1\end{minipage}};%
            \end{tikzpicture}%
         \end{center}%
}


\mybox{\textlatin{\blindtext}}


\end{document}

结果是这样的:

在此处输入图片描述

答案1

您可以添加一个参数来\mybox指定替代颜色。所以

\mybox{text} 

green将产生一个使用(定义中指定的默认颜色)的框mybox,但是

\mybox[red]{text}  

将使用red

在此处输入图片描述


不过,我建议你使用包裹mdframed反而:

在此处输入图片描述


代码:tikz节点

\documentclass[a4paper]{report}

\usepackage[greek]{babel}
\usepackage{xcolor}
\usepackage{blindtext}
\usepackage{tikz}


\newcommand{\mybox}[2][green]{%
         \begin{center}%
            \begin{tikzpicture}%
                \node[rectangle, draw=green, top color=#1!10, bottom color=#1!90, rounded corners=5pt, inner xsep=5pt, inner ysep=6pt, outer ysep=10pt]{%
                \begin{minipage}{1.05\linewidth}#2\end{minipage}};%
            \end{tikzpicture}%
         \end{center}%
}

\begin{document}
    \mybox{\textlatin{\blindtext}}
    \mybox[red]{\textlatin{\blindtext}}
    \mybox[blue]{\textlatin{\blindtext}}
\end{document}

代码:mdframed

\documentclass{report}

\usepackage[greek]{babel}
\usepackage{xcolor}
\usepackage{blindtext}
\usepackage[framemethod=tikz]{mdframed}

\newcommand{\mybox}[2][]{%
    \begin{mdframed}[backgroundcolor=green!70,roundcorner=10.0pt, #1]
        #2%
    \end{mdframed}
}%

\begin{document}
    \mybox{\textlatin{\blindtext}}
    \mybox[backgroundcolor=red!40]{\textlatin{\blindtext}}
    \mybox[backgroundcolor=blue!25]{\textlatin{\blindtext}}
\end{document}

答案2

因为你已经使用了 tikz 包彩色盒子是另一种选择。手册第 12 页将“mybox”描述为:

\newtcolorbox[⟨init options⟩]{⟨name⟩}[⟨number⟩][⟨default⟩]{⟨options⟩}⟨name⟩基于创建新环境tcolorbox。基本上,\newtcolorbox 操作方式与 类似\newenvironment。这意味着,新环境 ⟨name⟩可选地接受⟨number⟩参数,其中⟨default⟩是可选第一个参数的默认值。它们⟨options⟩被提供给底层 tcolorbox。

定理是用\tcbuselibrary{theorems}(见第 185 页)设置的。

\documentclass[a4paper]{report}

\usepackage[greek]{babel}
\usepackage[iso-8859-7]{inputenc}
\usepackage{xcolor}
\usepackage{blindtext}
\usepackage{tikz,tkz-tab,amsmath}
\usepackage{tcolorbox}
\newtcolorbox{mybox}{colback=red!5!white,colframe=red!75!black}
\newtcolorbox{mybox_1}{colback=blue!5!white,colframe=blue!75!black}
\newtcolorbox{mybox_2}{colback=green!5!white,colframe=green!75!black}
\tcbuselibrary{theorems}
\newtcbtheorem[number within=section]{mytheo}{My Theorem}%
{colback=green!5,colframe=green!35!black,fonttitle=\bfseries}{th}

\begin{document}

\chapter{Watt}
\section{James}

\begin{mybox}
\textlatin{This is my own box.}
\end{mybox}

\begin{mybox_1}
This is my own box.
\end{mybox_1}

\begin{mybox_2}
\begin{equation}
 V= \pi \cdot r^{2} \cdot h
 \end{equation}
\end{mybox_2}

\begin{mytheo}{This is my title}{theoexample}
\textlatin{This is the text of the theorem. The counter is automatically assigned and, in this example, prefixed with the section number. This theorem is numbered with \ref{th:theoexample} and is given on page\pageref{th:theoexample}.}
\end{mytheo}

\end{document}

在此处输入图片描述

相关内容