# Table (with caption) inside longtable

I need to put a tabular into a long table and assign a caption and a label to the "sub tabular". I tried putting the nested tabular into a table environment but it doesn't work:

\documentclass{article}
\usepackage{longtable}
\begin{document}
\begin{longtable}{c}
\begin{table}
\begin{tabular}{c}
test
\end{tabular}
\caption{my caption}
\label{tab:mysubtable}
\end{table}
\end{longtable}
\end{document}


I tried also to wrap the table environment in a minipage and to do without the table evironment, simulating the caption with \captionof{table}{my caption} but both attempts failed. I tried also using xltabular instead of longtable, but it didn't solve.

UPDATE
As @leandriis was pointing out I insert the motivation: I need to create a table of steps to solve a problem: each row contains the information related to a specific set of steps to solve the problem and in one column I have to put all the steps of the set. Since some set of steps can be reused in another set it's important to label the set of steps and to refer it. A simplified example:

start steps end
A "subtabular with images of steps, caption and label" B
B "subtabular with images of steps, caption and label" C
A Apply "1", then "2" C

The steps must be aligned and so a tabular is what I thought of, in the caption I will write the name of the algorithm (the set of steps) and use the label to refer to it in the next rows.

• Could you add some background information on why you would want to use a table with its caption inside of a longtable? Probably there is an entirely diffferent way to achieve the layout you would like to get. Dec 14, 2020 at 11:04
• @leandriis done. Thank you for attention
– DPD-
Dec 14, 2020 at 11:24
• I can see no use for the outer longtable. If there is no alignment between the various subtables (as in your current sketch) just have the tabular. If you want the same columns in all the subtabular remove the inner tabular and have a single longtable with multiple \caption Dec 14, 2020 at 12:02

I can simulate the caption and the label in this way:

\documentclass{article}
\usepackage{longtable, hyperref}

\newcounter{alg}
\newcommand\algcaption[1]{\refstepcounter{alg}\textbf{Algorithm \thealg:} #1}

\begin{document}
\begin{longtable}{c}
\begin{tabular}{c}
\begin{tabular}{cc}
test1 & test2
\end{tabular}\\
\algcaption{mycaption\label{alg:mylabel}}
\end{tabular}\\
See~\ref{alg:mylabel}
\end{longtable}
\end{document}