1

I'm a little new using the \newenvironment command, and i'm having a little problem here. I'm using the abstract-package to get a one-column abstract in a two-column article, which includes the \twocolumn command.

The problem is that i want to make a new environment, so i don't have to look at that bulky solution every time i'm writing my abstract, which means i wan't to do something like this:

\documentclass[twocolumn]{article}
\usepackage{abstract}

\title{Title}
\date{\today}
\author{Me}

\newenvironment{costumabstract}
    {   
        \twocolumn[
        \maketitle
        \begin{onecolabstract}\noindent
    }
    {
        \end{onecolabstract}\vspace{.5cm}
        ]
    }

\begin{document}

\begin{costumabstract}
    Abstract
\end{costumabstract}

\end{document}

This gives an error, as the square brackets of \twocolumn spans both the starting and ending conditions of my environment.

This means I have to use the \twocolumn command on my costumabstract environment in my text, and I would prefer to not do this ... Is there a workaround here?

0

2 Answers 2

1

This seems a task for the environ package, which lets you define an environment by grabbing its contents into a macro to be used freely.

\documentclass[twocolumn]{article}
\usepackage{abstract}
\usepackage{environ}
\usepackage{lipsum}

\title{Title}
\date{\today}
\author{Me}

\NewEnviron{costumabstract}{%
  \twocolumn[%
    \maketitle
    \begin{onecolabstract}\noindent
      \BODY
    \end{onecolabstract}\vspace{.5cm}%
  ]%
}

\begin{document}

\begin{costumabstract}
    \lipsum[1]
\end{costumabstract}

\lipsum[1-3]

\end{document}

screenshot

0

You may want to put the contents of your environment in a box first and then use this box inside the \twocolumn macro:

\documentclass[twocolumn]{article}
\usepackage{abstract,lipsum}

\title{Title}
\date{\today}
\author{Me}

\newenvironment{costumabstract}
  {   
    \newsavebox{\mybox}
    \begin{lrbox}{\mybox}\begin{minipage}{\dimexpr\textwidth-\absleftindent-\absrightindent\relax}
  }
  {
    \end{minipage}\end{lrbox}
    \twocolumn[
      \maketitle
      \begin{onecolabstract}\noindent\usebox{\mybox}
      \end{onecolabstract}\vspace{.5cm}
    ]
  }

\begin{document}

\begin{costumabstract}
   \lipsum[2]
\end{costumabstract}

\lipsum[1-3]

\end{document}

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .