Cross Reference of Environments

I defined a personalized table environment as follows:

\newcounter{Table}[section]
\newenvironment{Table}[1][]{
\refstepcounter{Table}
\newcommand{\tbtitle}{#1}
\begin{center}
}
{
\vspace{0.3cm}\\\textbf{\fontfamily{qag}\selectfont\color{black!80!blue}Table \thesection.\theTable} \fontfamily{ppl}\selectfont\textit{\tbtitle}\par
\end{center}
}


When I do Table \ref{table:1}, suppose the label exists, I only get Table 1. How can I also include chapter and section numbers so I get Table 3.1.1, for example?

• \renewcommand{\theTable}{\thesection.\arabic{Table}}, assuming that \thesection itself uses \thechapter.\arabic{section}}. \refstepcounter uses the \the.... of the counter being refstepped to generate the label value. If your \theTable contains only the standard \arabic{Table} setup, the label will be written as 1 etc. – user31729 Mar 18 '16 at 21:15
• By the way: Fragments as your code above aren't really useful -- provide a compilable document, not pieces of code that has to be glued together to get a running example – user31729 Mar 18 '16 at 21:19
• Thanks for answering my question again, Chris! It was really helpful. – Sekots Reivan Mar 18 '16 at 21:20
• You will only be able to use this environment once without error, though, because the command \tbtitle will exist after the first creation. Also, you are inserting spaces which you probably don't want so don't be surprised if you get weird spacing issues. In any case, it would probably be better to use a dedicated series of \captions for this kind of case so that you can, if you want, create a list of Tables or whatever. But whether you need that structure depends on the use, really, so it might be overkill. – cfr Mar 18 '16 at 21:56
• @cfr: \tbtitle is being defined within the environment -- it's in a group and is undefined outside. Try \meaning\tbtitle after calling the environment. – user31729 Mar 19 '16 at 15:28

This is a working version, but I don't recommend this wrapper environment actually.

\documentclass{book}

\usepackage{xcolor}

\newcounter{Table}[section]

\renewcommand{\theTable}{\thesection.\arabic{Table}}

\newenvironment{Table}[1][]{%
\refstepcounter{Table}
\newcommand{\tbtitle}{#1}
\begin{center}
}{%
\vspace{0.3cm}

\textbf{\fontfamily{qag}\selectfont\color{black!80!blue}Table \theTable} \fontfamily{ppl}\selectfont\textit{\tbtitle}\par
\end{center}
}

\begin{document}

\chapter{First}

\section{First}

\begin{Table}{Foo}
My nice table
\end{Table}

\begin{Table}{Foobar}
My other nice table
\end{Table}

\end{document}