
我想用不同的顏色製作彩色盒子,但我無法理解 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}