# Table issue inside a custom environment

I have a large document in which I use and reuse pieces of data. Such a piece of data consists of a number, a short and long description and a value. For example. I want to declare all those pieces of data in advance like this:

\begin{datasnippets}
\datasnippet{building}{An expensive house}{The address of a building costing more than 1 million}{1 Google Drive CA}
\end{datasnippets}


I then want this environment to (a) generate a table with all datasnippets, and (b) generate a set of commands which allow me to refer to the different parts of those snippets.

So, the above snippet followed by following sentence:

I found a license plate (\licenseplateValue ). The car was located at \buildingValue .


Will look like this.

Currently I implemented this as follows:

\newcounter{datasnippets}
\newcommand{\thedatasnippetcounter}{\arabic{datasnippets}}
\newenvironment{datasnippets}
{
\small\\
\hspace{-2cm}\begin{longtable}{p{0.4cm} p{4cm}p{3cm}p{10cm} }
\ & \textbf{Naam} & \textbf{Waarde} & \textbf{Beschrijving} \\
\ & \ & \ & \\
\hline
\newcommand{\datasnippet}[4]{%
\refstepcounter{datasnippets}
\label{data:##1}
\global\expandafter\def\csname ##1\endcsname{##2}
\global\expandafter\def\csname ##1Description\endcsname{##3}%
\global\expandafter\def\csname ##1Value\endcsname{##4}%
\global\expandafter\def\csname ##1Full\endcsname{##3 (waarde: ##4)}%

\hspace{-2cm}
\begin{tabular}{p{0.2cm}p{4cm}p{3cm}p{10cm} }
\thedatasnippetcounter . & ##2 & ##4 & ##3 \\
\ & \ & \ & \\
\end{tabular}
}
}
{
\end{longtable}
}


The result somewhat behaves the way I want it to, but the table behaves very badly when it gets too long as it doesn't break over pages. Also, the fact that I use tabulars inside a tabular is a poor mans solution, since I didn't get it to work without the inner tabular (and I have no idea why - the outer tabular is open and only closed at the very end?).

So my question is: how do I get this working without the second tabular and how do I get the table to break nicely over multiple pages?

Thanks,

It's not clear what the inner tabular is for:

\documentclass{article}

\usepackage[
left=1cm,
right=1cm,
textheight=3cm, % just to make the example smaller
]{geometry}

\usepackage{longtable}

\newcounter{datasnippets}
\newcommand{\datasnippet}[4]{%
\refstepcounter{datasnippets}\label{data:#1}%
\global\expandafter\def\csname #1\endcsname{#2}%
\global\expandafter\def\csname #1Description\endcsname{#3}%
\global\expandafter\def\csname #1Value\endcsname{#4}%
\global\expandafter\def\csname #1Full\endcsname{#3 (waarde: #4)}%
\thedatasnippets. & #2 & #4 & #3 \\
}
\newenvironment{datasnippets}
{\par
\small
\begin{longtable}{p{0.4cm}p{4cm}p{3cm}p{10cm}}
& \textbf{Naam} & \textbf{Waarde} & \textbf{Beschrijving} \\
\hline
}
{%
\end{longtable}
}

\begin{document}

\begin{datasnippets}
{1BEL500}
\datasnippet{building}
{An expensive house}
{The address of a building costing more than 1 million}
\datasnippet{building2}
{An expensive house}
{The address of a building costing more than 1 million}
\datasnippet{building3}
{An expensive house}
{The address of a building costing more than 1 million}
\datasnippet{building4}
{An expensive house}
{The address of a building costing more than 1 million}
\datasnippet{building5}
{An expensive house}
{The address of a building costing more than 1 million}
\datasnippet{building6}
{An expensive house}
{The address of a building costing more than 1 million}
\datasnippet{building7}
{An expensive house}
{The address of a building costing more than 1 million}
\end{datasnippets}

I found a license plate (\licenseplateValue). The car was located at \buildingValue.

\end{document}


Of course you need to set the lengths so that you don't overflow the text width.

Here's a different implementation:

\documentclass{article}

\usepackage{longtable,array}

\newcounter{datasnippets}
\newcommand{\datasnippet}[4]{%
\refstepcounter{datasnippets}\label{data:#1}%
\global\expandafter\def\csname #1\endcsname{#2}%
\global\expandafter\def\csname #1Description\endcsname{#3}%
\global\expandafter\def\csname #1Value\endcsname{#4}%
\global\expandafter\def\csname #1Full\endcsname{#3 (waarde: #4)}%
\thedatasnippets. & #2 & #4 & #3 \\
}
\newenvironment{datasnippets}
{\par
\small
\begin{longtable}{
p{0.4cm}
p{4cm}
p{3cm}
>{\raggedright\arraybackslash}p{\dimexpr\textwidth-8\tabcolsep-0.4cm-4cm-3cm\relax}
}
& \textbf{Naam} & \textbf{Waarde} & \textbf{Beschrijving} \\
\hline
}
{%
\end{longtable}
}

\begin{document}

\begin{datasnippets}
{1BEL500}
\datasnippet{building}
{An expensive house}
{The address of a building costing more than 1 million}
\datasnippet{building2}
{An expensive house}
{The address of a building costing more than 1 million}
\datasnippet{building3}
{An expensive house}
{The address of a building costing more than 1 million}
\datasnippet{building4}
{An expensive house}
{The address of a building costing more than 1 million}
\datasnippet{building5}
{An expensive house}
{The address of a building costing more than 1 million}
\datasnippet{building6}
{An expensive house}
{The address of a building costing more than 1 million}