# How to put environment text inside node?

Consider a simple environment in the documentclass as

  \newenvironment{abstract}{
\node (tbl) {

};
}


The content of

\begin{abstract}
Content
\end{abstract}


will goes after the node. How to put the content inside the node? The node has been used by tikzpicture to draw picture backgrounds.

This can also apply to Section: how we can put the section header and text inside a node? a simple section header is as

\newcommand\section{\@startsection {section}{1}{\z@}%
{-3.5ex \@plus -1ex \@minus -.2ex}%
{2.3ex \@plus.2ex}%
{\normalfont\Large\bfseries}}


This only defines the section header text. How we can play with the section header and text within node?

UPDATE: an example in reference to discussion with @MartinScharrer

  \newenvironment{abstract}{
\begin{center}
\begin{tikzpicture}
\node (x) {
This is inside node
};
\begin{pgfonlayer}{background}
\draw[rounded corners, top color=red, bottom color=black, draw=white]
($(x.north west)+(0.14,0)$) rectangle ($(x.north east)-(0.13,0.9)$);
\end{pgfonlayer}
\end{tikzpicture}
\end{center}
}

-
AFAIK abstract contains a paragraph break, but the normal node doesn't allow paragraphs. Either place the content in a minipage or \parbox manually or use a TikZ option which does this. I think text width or some align option does that. – Martin Scharrer Apr 17 '12 at 13:16
Could you add a minimal working example (MWE) that shows your effort so far as well as the exact application. Is the new abstract environment used inside a manual tikzpicture or should create one by itself. Do you want to do this in order to add decorations or to reference to the node later? – Martin Scharrer Apr 17 '12 at 13:20
@MartinScharrer Abstract was a typical example, I am talking in general and even for a section. Transferring a part of the text gives us more power to design with different packages (IMHO). And this will be only for decoration purpose. – All Apr 17 '12 at 13:21
The precise question still scapes me: do you mean you already have a background previously drawn with tikz, and in that background you defined a node (tbl) in this case, and now you want to add things "on top"? – Koji Apr 17 '12 at 13:26
@Koji see the example in UPDATE. I want to display the abstract content inside the node as it does for This is inside node. – All Apr 17 '12 at 13:28

You can split the code of a \node by replacing the { and } with \bgroup and \egroup. This is possible because TikZ reads the content of the node as box and not as macro argument. Note that you need to set special options to allow for paragraph or line breaks inside the node or add a minipage (or varwidth) environment.

\newenvironment{abstract}[1][]{% most likely \renewenvironment!
\begin{tikzpicture}[<picture options>]
\node [<default options>,#1] (tbl) \bgroup
%\begin{minipage}{<some width>}
}{%
%\end{minipage}
\egroup;
\end{tikzpicture}%
}


Usage:

\begin{abstract}
My abstract ...
\end{abstract}


An alternative is to use the environ package to collect the whole environment content as \BODY and then use \node [<options>] (<name>) {\BODY};.

-
Very subtle trick! Thanks it will be tricky approach for other usages too. – All Apr 17 '12 at 13:46

This might work for short pieces of text but in general it's not a good idea to relieve TeX from its killer text adjustment duties and placing text into a node makes it immune to many TeX goodies.

\documentclass{article}
\usepackage{amsmath,tikz,lipsum}
\newcommand{\tikzabstract}[1]{
\begin{abstract}
\tikz[trim left=-4.7cm]\node[draw,text justified,text width=\textwidth] (tbl) {#1};
\end{abstract}
}
\begin{document}
\tikzabstract{\lipsum[1-2]}
\lipsum[3-4]
\end{document}


For some reason I had to trim the left side to center the node otherwise it has a shift towards right (probably due to the fact that abstract environment modifies the text width). But can be automated once the text width and page width is known.

-