\documentclass{article}
\usepackage[many]{tcolorbox}
\usepackage{lipsum}
\tcbset{myoption/.style={colback=blue!20}}
\newcommand{\bubble}[1]{%
\begin{tcolorbox}[myoption]
#1
\end{tcolorbox}
}
\begin{document}
\bubble{\lipsum[1][1-2]}
\end{document}
我从这里有这个代码。
我想定义自己的环境并使用其中的宏。
\begin{document}
\begin{myenvironment}
\bubble{\lipsum[1-2]}
\end{myenvironment}
\end{document}
答案1
取决于您想在这个环境中放置什么,但这是第一个例子。
%%%%%%% preamble %%%%%%%%
\usepackage{enumerate,enumitem} %for lists
\usepackage[most]{tcolorbox}
\newtcolorbox{specifications}[1][]{%
enhanced, width=0.9\textwidth ,center,
colback=blue!5!white,colframe=blue!85!black,
attach boxed title to top center={yshift=-3mm,yshifttext=-1mm},title=\textbf{Specifications},
boxed title style={colframe=blue!85!black,colback=blue!85!black},#1}
%%%%%%% document %%%%%%%%
\begin{specifications}
This project deals with synthesing and characterizing lanthanide-based MOFs to investigate if these materials can be used as platforms for detecting selected VOCs. The tasks to be completed are listed below.
\begin{enumerate}[label=\textbullet]
\item Read literature on MOFs
\item Plan the experimental work
\item Carry out the syntheses of different lanthanide-based MOF
\item Characterize synthesized MOF
\item Investigate the porosity, stability, and luminescent properties of the synthesized MOFs
\end{enumerate}
\end{specifications}
出于某种原因,如果您的环境需要说明,那么这里就有一个可行的方法。
下一个示例展示了一种包含可在“代码列表”中列出的代码的方法。
%%%%%%%%%% preamble %%%%%%%%%%%%%
\usepackage[most]{tcolorbox} %for box
\usepackage[table,dvipsnames]{xcolor}
\usepackage{newfloat} %create floating environment (such as Figure, Table, ...)
\usepackage{capt-of} %caption for non-floating environement / breakable envir.
%% list of codes (for matlab codes) %listofcodes
\DeclareFloatingEnvironment[name={Code},fileext={loc},listname={List of Codes}]{code}
\usepackage{listings} %IT in latex
\usepackage{matlab-prettifier} %upgrade of listings specific to matlab code
%%%%%%%%%% document %%%%%%%%%%%%%
\captionof{code}{Matlab code for TGA computations}\label{code:TGA_calculations} % place the caption
\begin{tcolorbox}[breakable,arc=0mm,left=1pt, right=1pt, boxrule=1mm,colback=BrickRed!5!white,colframe=BrickRed!85!black]
\begin{lstlisting}[language=Matlab, numbers=left, style=Matlab-editor]
%code
\end{lstlisting}
\end{tcolorbox}
该breakable
选项允许将环境显示在多个页面上。
我认为第二个选项可以像第一个一样优化为一个页面,\newenvironment
但这只是举例而已。
如果你想尝试其他的东西,你可以尝试阅读手册tcolorbox
。
“技术概述和定制”部分可能会对您的问题有所帮助。
祝你好运