Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

Is there a way to add a background color to the abstract? I tried various combinations of \colorbox and the \begin{abstract} ... \end{abstract} environment, but nothing worked.

I use the current TexShop version with default setting. Here is my preamble:

\documentclass[12pt,twocolumn]{amsart}
\usepackage{geometry}                   
\usepackage{graphicx}
\usepackage[superscript]{cite}
\usepackage{amssymb}
\usepackage{upgreek}
\usepackage[usenames,dvipsnames]{xcolor}
\usepackage{wallpaper}
\usepackage[size=normalsize,format=plain,textfont=sc]{caption}

\bibstyle{alpha}
\geometry{a4paper}                      

\title{some title}
\author{the author}
\date{} % delete this line to display the current date

\begin{document}
\onecolumn
\maketitle

\begin{abstract}

Lorem ipsum dolor sit amet, 

\end{abstract}

\tableofcontents

\twocolumn
\input{1}

\input{2}

\input{3}

\input{4}

\bibliographystyle{plain}
\bibliography{Lit}

\end{document}
share|improve this question
    
Welcome to TeX.SE. One option would be to use \usepackage{xcolor,mdframed}, and wrap the abstract in \begin{mdframed}[backgroundcolor=yellow!10], \end{mdframed}`. –  Peter Grill Jun 13 '12 at 1:11
    
@PeterGrill this will not work with amsart due to the way it handles the abstract. –  Gonzalo Medina Jun 13 '12 at 2:26

2 Answers 2

up vote 6 down vote accepted

In the standard article class it would suffice to wrap the abstract environment inside some appropriate element (a \colorbox, for example); however, since you are using amsart, additional work is required: you need to redefine the abstract environment to use, for example, a mdframed environment (from the mdframed package) with the desired background color; a little example:

\documentclass{amsart}
\usepackage{geometry}                   
\usepackage{xcolor}
\usepackage{mdframed}
\usepackage{lipsum}% just to generate some text

\geometry{a4paper}                      

\makeatletter
\renewenvironment{abstract}{%
  \ifx\maketitle\relax
    \ClassWarning{\@classname}{Abstract should precede
      \protect\maketitle\space in AMS documentclasses; reported}%
  \fi
  \global\setbox\abstractbox=\vtop \bgroup
    \normalfont\Small
    \list{}{\labelwidth\z@
      \leftmargin3pc \rightmargin\leftmargin
      \listparindent\normalparindent \itemindent\z@
      \parsep\z@ \@plus\p@
      \let\fullwidthdisplay\relax
    }%
    \item[]\vskip-\baselineskip
    \begin{mdframed}[backgroundcolor=blue!20,hidealllines=true]
    \item[\hskip\labelsep\scshape\abstractname.]%
}{%
  \end{mdframed}\endlist\egroup
  \ifx\@setabstract\relax \@setabstracta \fi
}
\makeatother

\title{some title}
\author{the author}
\date{} % delete this line to display the current date

\begin{document}

\begin{abstract}
\lipsum[4]
\end{abstract}

\maketitle

\lipsum[2]

\end{document}

enter image description here

On a side note, the abstract environment must be placed before \maketitle when using amsart.

Here's another option using the framed package:

\documentclass{amsart}
\usepackage{geometry}                   
\usepackage{xcolor}
\usepackage{framed}
\usepackage{lipsum}% just to generate some text

\geometry{a4paper}                      

\colorlet{shadecolor}{blue!20}

\makeatletter
\renewenvironment{abstract}{%
  \ifx\maketitle\relax
    \ClassWarning{\@classname}{Abstract should precede
      \protect\maketitle\space in AMS documentclasses; reported}%
  \fi
  \global\setbox\abstractbox=\vtop \bgroup\begin{shaded}
    \normalfont\Small
    \list{}{\labelwidth\z@
      \leftmargin3pc \rightmargin\leftmargin
      \listparindent\normalparindent \itemindent\z@
      \parsep\z@ \@plus\p@
      \let\fullwidthdisplay\relax
    }%
   \item[\hskip\labelsep\scshape\abstractname.]%
}{%

\endlist\end{shaded}\egroup
  \ifx\@setabstract\relax \@setabstracta \fi
}
\makeatother

\title{some title}
\author{the author}
\date{} % delete this line to display the current date

\begin{document}

\begin{abstract}
\lipsum[4]
\end{abstract}

\maketitle

\lipsum[2]

\end{document}
share|improve this answer
    
That is exactly what I was looking for! Unfortunately I cannot reproduce it, neither with my file nor when I copy/paste your example file and try to run it. In either case, I receive the following error message: ./test.tex:38: Package keyval Error: hidealllines undefined. See the keyval package documentation for explanation. Type H <return> for immediate help. ... l.38 \begin{abstract} ? –  tgraf Jun 13 '12 at 10:52
1  
@tgraf the error indicates that you have an outdated version of the mdframed package; you can update your LaTeX installation. In the meantime I provided another solution using this time the framed package. –  Gonzalo Medina Jun 13 '12 at 11:29
    
As it turned out, I had an outdated version of a zillion of packages. Working like a charm now. Thanks. –  tgraf Jun 13 '12 at 16:05

if you want the color box the same width as the text then put it into a minipage

\documentclass{amsart}
\usepackage{xcolor}
\usepackage{mdframed}
\usepackage{lipsum}
\let\Abstract\abstract
\long\def\abstract{\mdframed[backgroundcolor=blue!20,hidealllines=true]
  \vspace*{-0.5\baselineskip}\Abstract}
\let\endAbstract\endabstract
\def\endabstract{\endAbstract\endmdframed\par\bigskip}

\title{some title}
\author{the author}

\begin{document}
\maketitle
\begin{abstract}
\lipsum[4]
\end{abstract}

\lipsum[2]

\end{document}

enter image description here

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.