创建一个灰色的抽象环境

创建一个灰色的抽象环境

您好,我想创建一个新环境:带有灰色背景的摘要。但是,我的环境中的文本不在灰色背景内。我该如何将摘要的内容插入灰色颜色框内?

\documentclass[11pt,twoside,twocolumn]{ieeetran}
\usepackage[left=20mm,right=20mm,top=20mm,bottom=20mm]{geometry}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
%colors
\usepackage[table]{xcolor}
%boxes 
\usepackage{awesomebox}
\usepackage{tcolorbox}
\usepackage{fancybox}
%figures
\usepackage{graphicx}
\usepackage{caption}
\usepackage{subcaption}
% for page background, abstract backgroun
%\usepackage{background}
%%%%
\title{My first article with two columns : ieeetran class}
\author{Author}
\date{\today}
%%%%
%\newenvironment{name}[numarg][optarg_default]{begin_def}{end_def}
%\rule[raise-height]{width}{thickness}
\newenvironment{myabstract}[1][]{
\rule{1\textwidth}{0.9pt}
\begin{center}
\colorbox{gray!35}{
\begin{minipage}{0.9\textwidth}
\textit{ABSTRACT} \par 
\textit{#1}
\end{minipage}}
\end{center}}
{ \par 
\rule{1\textwidth}{0.9pt}
}
\begin{document}
\maketitle
\begin{myabstract} ~~\\
This is a test
\end{myabstract}
\end{document}

在此处输入图片描述

答案1

像这样吗?

\documentclass[11pt,a4paper]{article}

\usepackage[margin=2cm]{geometry}
\usepackage[many]{tcolorbox}    

\newtcolorbox{abst}{enhanced, colback=gray!30, colframe=gray!60, width=\linewidth,size=fbox, oversize=2pt, boxrule=0pt, toprule=1pt, bottomrule=1pt, sharp corners, boxsep=3pt, top=6pt, bottom=6pt, breakable=true,coltext=black,fontupper=\sffamily\itshape\small, title={ABSTRACT}}

\begin{document}
    
    \begin{abst}
        This is an example of an abstract inside a gray box
    \end{abst}

\end{document}

您必须尝试调整 tcolorbox 的设置,使其符合 的要求ieeetran class。阅读 手册tcolorbox以了解标题格式选项

答案2

另一个解决方案是。中的tcolorbox原始内容被限制在左栏中。abstractieeetran.cls

\documentclass[11pt,twoside,twocolumn]{ieeetran}
\usepackage[left=20mm,right=20mm,top=20mm,bottom=20mm]{geometry}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
%colors
\usepackage[table]{xcolor}
%boxes 
\usepackage{awesomebox}
\usepackage[most]{tcolorbox}
\usepackage{fancybox}
%figures
\usepackage{graphicx}
\usepackage{caption}
\usepackage{subcaption}
% for page background, abstract backgroun
%\usepackage{background}
%%%%
\title{My first article with two columns : ieeetran class}
\author{Author}
\date{\today}
%%%%
\newtcolorbox{myabstract}[1][]{
    enhanced,
    width=.9\linewidth,
    sharp corners,
    frame hidden,
    borderline north={.9pt}{-2pt}{black},
    borderline south={.9pt}{-2pt}{black},   
    center,
    colback=gray!35,
    title=ABSTRACT,
    fontupper=\itshape,
    coltitle=black,
    attach title to upper={\\},
    #1
}

\begin{document}
\maketitle

\begin{myabstract}
This is a test
\end{myabstract}

\section{One}

Some text
\end{document}

在此处输入图片描述

相关内容