# Create new glossaries style with tabularx

I'm using the glossaries package and I'm trying to create my own style for printing the glossary. Specifically, I'd like my glossary to appear in a particularly formatted tabularx table. I've been trying to refer to the documentation, but they don't go into that much detail concerning this and the only other resource I could find was this answer which now appears to be out of date as even the provided answer doesn't work for me.

Ultimately, what I have in my MWE below fails with a misplaced \noalign issue. Can anyone show me a way to create the glossary using the table format I'm trying to achieve?

Minimum (non-)Working Example

\documentclass{article}

\usepackage[table]{xcolor}      % Provides coloring for tables and text
\usepackage{tabularx}           % Customized table formatting
\usepackage{environ}        % Used to define custom table environment
\usepackage[acronym]{glossaries}

% Define table related commands and properties
\definecolor{greyblue}{rgb}{0.6353,0.6863,0.7686} % Define a color used in the tables
\newcommand\setrow[1]{\gdef\rowmac{#1}#1\ignorespaces} % Used for making a row bold
\newcommand\clearrow{\global\let\rowmac\relax} \clearrow % Used for clearing a row formatting
\newcolumntype{C}[1]{>{\hsize=#1\hsize\rowmac\centering\arraybackslash}X} % Centered column, input is relative width of page
\newcolumntype{L}[1]{>{\hsize=#1\hsize\rowmac\raggedright\arraybackslash}X} % Left-aligned column, input is relative width of page
\newcolumntype{R}[1]{>{\hsize=#1\hsize\rowmac\raggedleft\arraybackslash}X} % Left-aligned column, input is relative width of page

\makenoidxglossaries

\newglossarystyle{docstyle}
{%
\renewenvironment{theglossary}
{%
\table[!htbp]
\centering
\rowcolors{2}{black!5}{black!15}
\tabularx{\linewidth}{C{0.25}|L{0.75}<{\clearrow}}%
\hline
\rowcolor{greyblue} \setrow{\bfseries} % Make the header row bold and colored grey-blue
}{
\hline
\endtabularx
\caption{Abbreviations}
\label{tbl:abbrev}
\endtable
}
% Don't do anything between letter groups
\renewcommand*{\glsgroupskip}{}%
% Set display for each the acronym entry
\renewcommand{\glossentry}[2]{%
\glstarget{##1}{\glsentryshort{##1}}% short form
&
\glsentrylong{##1}% long form
\\% end of row
}%
}

\newacronym{ABC}{ABC}{Alphabet}

\begin{document}
\gls{ABC}
\gls{ABC}

\printnoidxglossary[type=\acronymtype,style=docstyle]
\end{document}


After playing around, I found an answer that works for me. It turns out the problem with the above code is the \hline in the closing environment. If this is removed, the problem is solved and the table is created nicely. However, This means I don't get the line below my table like I want.

To get the table formatted precisely how I wanted, I had to use the environ package. This allows me to create a nice table environment that works how I want, and that table environment can be used to define the glossary style. Below is a MWE that works precisely as I wanted.

\documentclass{article}

\usepackage[table]{xcolor}      % Provides coloring for tables and text
\usepackage{tabularx}           % Customized table formatting
\usepackage{environ}        % Used to define custom table environment
\usepackage[acronym]{glossaries}

% Define table related commands and properties
\definecolor{greyblue}{rgb}{0.6353,0.6863,0.7686} % Define a color used in the tables
\newcommand\setrow[1]{\gdef\rowmac{#1}#1\ignorespaces} % Used for making a row bold
\newcommand\clearrow{\global\let\rowmac\relax} \clearrow % Used for clearing a row formatting
\newcolumntype{C}[1]{>{\hsize=#1\hsize\rowmac\centering\arraybackslash}X} % Centered column, input is relative width of page
\newcolumntype{L}[1]{>{\hsize=#1\hsize\rowmac\raggedright\arraybackslash}X} % Left-aligned column, input is relative width of page
\newcolumntype{R}[1]{>{\hsize=#1\hsize\rowmac\raggedleft\arraybackslash}X} % Left-aligned column, input is relative width of page

\makenoidxglossaries

\NewEnviron{doctable}[4]{%
\begin{table}[!htbp]
\centering
\rowcolors{2}{black!5}{black!15}
\begin{tabularx}{#3\linewidth}{#4<{\clearrow}}%
\hline
\rowcolor{greyblue} \setrow{\bfseries} % Make the header row bold and colored grey-blue
\BODY
\hline
\end{tabularx}
\caption{#2}
\label{#1}
\end{table}
}

\newglossarystyle{docstyle}
{%
\renewenvironment{theglossary}
{%
\doctable
{tbl:abbrev}
{Abbreviations}
{1} { L{0.2}|L{0.8} }
Abbreviation & Description \\
}{
\enddoctable
}
\renewcommand{\glossarysection}[2][]{}
% Don't do anything between letter groups
\renewcommand*{\glsgroupskip}{}%
% Set display for each the acronym entry
\renewcommand{\glossentry}[2]{%
\glstarget{##1}{\glsentryshort{##1}}% short form
&
\glsentrylong{##1}% long form
\\% end of row
}%
}

\newacronym{ABC}{ABC}{Alphabet}
\newacronym{GHI}{GHI}{test}
\newacronym{DEF}{DEF}{Some other acronym}

\begin{document}
\gls{ABC}
\gls{ABC}
\gls{DEF}

\printnoidxglossary[type=\acronymtype,style=docstyle]
\end{document}


This produces: