# Reference table rows differently in multiple tables in LaTeX

I'm making an interview. I have a table with "Questions and Explanations" and a table with "Questions and Answers". I have labeled each row, so I can reference each question later on. I would like to change the labeling, and also reference my Questions and Answers table different for each interview person: I would like to number and label each row in my table so I can reference them later on.

I get the following output:

I would like the output to look like this:

My code is:

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{graphicx}
\usepackage[danish]{babel}
\usepackage{lscape}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{color}
\usepackage[usenames,dvipsnames,svgnames,table]{xcolor}
\usepackage{float}
\usepackage[top=2.81cm, bottom=2.75cm,right=2cm, left=2cm]{geometry}
\usepackage{url}
\usepackage{setspace}
\onehalfspacing
\usepackage[T1]{fontenc}

%%% DETTE ER NUMERERING AF RÆKKER I TABELLER
\usepackage{etoolbox}
\usepackage{setspace}
\onehalfspacing
\usepackage{url}
\newcounter{rowcntr}[table]
\makeatletter
% Assuming arabic numbers for the table number -- in case of bottom table caption, we have to increase the table number by one, only for output.
\usepackage{longtable}
\newcolumntype{L}[1]{>{\raggedright\let\newline\\\arraybackslash\hspace{0pt}}m{#1}}
\newcolumntype{V}[1]{>{\raggedright\let\newline\\\arraybackslash}p{\dimexpr#1-2\tabcolsep-\arrayrulewidth}}
\newcolumntype{C}[1]{>{\centering\let\newline\\\arraybackslash\hspace{0pt}}m{#1}}
\renewcommand{\therowcntr}{\@arabic{\numexpr\c@table+1}.\arabic{rowcntr}}
\makeatother
\newcolumntype{N}{>{\refstepcounter{rowcntr}\therowcntr}c}
\AtBeginEnvironment{tabular}{\setcounter{rowcntr}{0}}
%%% DETTE ER NUMERERING AF RÆKKER I TABELLER
\begin{document}
\section*{Interview questions}
The following table contains my interview questions and explanation

\begin{center}
\begin{longtable}{|N| c | V{7.6cm} | V{7.6cm} |}
\hline
\multicolumn{2}{|c}{} & \multicolumn{1}{c|}{\textbf{Question}} & \multicolumn{1}{c|}{\textbf{Explanation}} \\ \hline
\multicolumn{4}{|c|}{Interview phase 1}\\ \hline
\multicolumn{4}{|C{17.5cm}|}{\textit{Text This phase focus on ...TextTextTextTextText TextTextTextTextTextTextTextTextTextTextText TextText TextTextText TextTextTextTextTextTextTextTextTextText Text Text Text Text Text Text Text Text }}\\ \hline
\label{que:1} & A & Do you think ...? & This is a good question.\\
\label{que:2} & C & Do you feel Text & This is a good question.\\
\label{que:3} & E & What do you think of your previous boss & Relationship between employee and employer text Text textText text Text text Text text.\\ \hline
\multicolumn{4}{|c|}{Interview phase 2}\\ \hline
\multicolumn{4}{|C{17.5cm}|}{\textit{Text This phase focus on ... }}\\ \hline
\label{que:4} & D & Is this ...? & Good question.\\
\label{que:5} & I & Do you like Text  & A good question.\\
\label{que:6} & A & what do you think of your mother & Relationship \\ \hline

\caption {Questions and explanation} \label{tab:interviewspg}
\end{longtable}
\end{center}
The following section contains the answers from interviewperson A
\begin{center}
\begin{longtable}{|N|  V{8.3cm} | V{8.3cm} |}
\hline
\multicolumn{1}{|c}{} & \multicolumn{1}{c|}{\textbf{Question}} & \multicolumn{1}{c|}{\textbf{Answer}} \\ \hline
\label{QA:1} &  Do you think ...? & Yes I think.\\
\label{QA:2} &  Do you feel Text & I feel a lot of text.\\
\label{QA:3} & What do you think of your previous boss & I hated him.\\
\label{QA:3a} & \textbf{This is an unexpected follow up question} \textbf{Why did you hate him?} & \textbf{Because he was evil.}\\
\label{QA:4} &  Is this ...? & Yes\\
\label{QA:5} & Do you like Text  & Text is good.\\
\label{QA6:6} & what do you think of your mother & I really like my mother \\ \hline

\end{longtable}
\end{center}

\newpage
The following section contains the answers from interviewperson B
\begin{center}
\begin{longtable}{|N|  V{8.3cm} | V{8.3cm} |}
\hline
\multicolumn{1}{|c}{} & \multicolumn{1}{c|}{\textbf{Question}} & \multicolumn{1}{c|}{\textbf{Answer}} \\ \hline
\label{QB:1} &  Do you think ...? & No\\
\label{QB:2} &  Do you feel Text & No you can't feel text\\
\label{QB:3} & What do you think of your previous boss & She was okay\\
\label{QB:4} &  Is this ...? & No\\
\label{QB:5} & Do you like Text  & Text is bad.\\
\label{QA6:6} & what do you think of your mother & I would like to not answer that \\ \hline

\end{longtable}
\end{center}
\end{document}

• As I can see you you have used code from my answer to your other question ;-) This is possible, of course, but the usual approach is to give at least some indication who wrote the originals of this (regardless who it is) – user31729 Mar 10 '17 at 20:27
• How can I indicate that you (or someone else) wrote the original code? :-) – Jonas Mar 10 '17 at 23:09

Here's an approach with a separate interviewee counter and a \subquest command to change temporarily the row counter format and providing a correct label for this.

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{graphicx}
\usepackage[danish]{babel}
\usepackage{lscape}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{color}
\usepackage[usenames,dvipsnames,svgnames,table]{xcolor}
\usepackage{float}
\usepackage[top=2.81cm, bottom=2.75cm,right=2cm, left=2cm]{geometry}
\usepackage{setspace}
\onehalfspacing
\usepackage[T1]{fontenc}

%%% DETTE ER NUMERERING AF RÆKKER I TABELLER
\usepackage{etoolbox}
\usepackage{setspace}
\onehalfspacing
\usepackage{url}
\newcounter{rowcntr}

\newcounter{interviewee}
\newcounter{subquestion}

\renewcommand{\theinterviewee}{\Alph{interviewee}}

% This is meant for a subquestion
\newcommand{\subquest}{%
\stepcounter{subquestion}%
\let\origtherowcntr\therowcntr%
\renewcommand{\therowcntr}{\origtherowcntr.\alph{subquestion}}%
\refstepcounter{rowcntr}%
}

\makeatletter
\newcommand{\prepareresultsections}{%
\setcounter{rowcntr}{0}
% Change the rowcntr format for the interview results
\renewcommand{\therowcntr}{\theinterviewee.\arabic{rowcntr}}
}
\makeatother

\newcommand{\resultsection}[1]{%
\clearpage
\refstepcounter{interviewee}%
\section*{#1}%
}

\makeatletter
% Assuming arabic numbers for the table number -- in case of bottom table caption, we have to increase the table number by one, only for output.
\usepackage{longtable}
\newcolumntype{L}[1]{>{\raggedright\let\newline\\\arraybackslash\hspace{0pt}}m{#1}}
\newcolumntype{V}[1]{>{\raggedright\let\newline\\\arraybackslash}p{\dimexpr#1-2\tabcolsep-\arrayrulewidth}}
\newcolumntype{C}[1]{>{\centering\let\newline\\\arraybackslash\hspace{0pt}}m{#1}}
%\renewcommand{\therowcntr}{\@arabic{\numexpr\c@table+1}.\arabic{rowcntr}}
\makeatother
\newcolumntype{N}{>{\refstepcounter{rowcntr}\therowcntr}c}
\AtBeginEnvironment{tabular}{\setcounter{rowcntr}{0}\setcounter{subquestion}{0}}
%%% DETTE ER NUMERERING AF RÆKKER I TABELLER
\begin{document}

\section*{Interview questions}
The following table contains my interview questions and explanation

\begin{center}
\begin{longtable}{|N| c | V{7.6cm} | V{7.6cm} |}
\hline
\multicolumn{2}{|c}{} & \multicolumn{1}{c|}{\textbf{Question}} & \multicolumn{1}{c|}{\textbf{Explanation}} \\ \hline
\multicolumn{4}{|c|}{Interview phase 1}\\ \hline
\multicolumn{4}{|C{17.5cm}|}{\textit{Text This phase focus on ...TextTextTextTextText TextTextTextTextTextTextTextTextTextTextText TextText TextTextText TextTextTextTextTextTextTextTextTextText Text Text Text Text Text Text Text Text }}\\ \hline
\label{que:1} & A & Do you think ...? & This is a good question.\\
\label{que:2} & C & Do you feel Text & This is a good question.\\
\label{que:3} & E & What do you think of your previous boss & Relationship between employee and employer text Text textText text Text text Text text.\\ \hline
\multicolumn{4}{|c|}{Interview phase 2}\\ \hline
\multicolumn{4}{|C{17.5cm}|}{\textit{Text This phase focus on ... }}\\ \hline
\label{que:4} & D & Is this ...? & Good question.\\
\label{que:5} & I & Do you like Text  & A good question.\\
\label{que:6} & A & what do you think of your mother & Relationship \\ \hline

\caption {Questions and explanation} \label{tab:interviewspg}
\end{longtable}
\end{center}

\prepareresultsections
The following section contains the answers from interviewperson \theinterviewee
\begin{center}
\begin{longtable}{|N|  V{8.3cm} | V{8.3cm} |}
\hline
\multicolumn{1}{|c}{} & \multicolumn{1}{c|}{\textbf{Question}} & \multicolumn{1}{c|}{\textbf{Answer}} \\ \hline
\label{QA:1} &  Do you think ...? & Yes I think.\\
\label{QA:2} &  Do you feel Text & I feel a lot of text.\\
\label{QA:3} & What do you think of your previous boss & I hated him.\\
\multicolumn{1}{|c|}{\subquest\therowcntr\label{QA:3a}} & \textbf{This is an unexpected follow up question} \textbf{Why did you hate him?} & \textbf{Because he was evil.}\\
\label{QA:4} &  Is this ...? & Yes\\
\label{QA:5} & Do you like Text  & Text is good.\\
\label{QA6:6} & what do you think of your mother & I really like my mother \\ \hline

\end{longtable}
\end{center}

The following section contains the answers from interviewperson \theinterviewee

\begin{center}
\begin{longtable}{|N|  V{8.3cm} | V{8.3cm} |}
\hline
\multicolumn{1}{|c}{} & \multicolumn{1}{c|}{\textbf{Question}} & \multicolumn{1}{c|}{\textbf{Answer}} \\ \hline
\label{QB:1} &  Do you think ...? & No\\
\label{QB:2} &  Do you feel Text & No you can't feel text\\
\label{QB:3} & What do you think of your previous boss & She was okay\\
\label{QB:4} &  Is this ...? & No\\
\label{QB:5} & Do you like Text  & Text is bad.\\
\label{QB:6} & what do you think of your mother & I would like to not answer that \\ \hline