Graphics, Figures & TablesKeep table to row reference after shifting rows

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
paulvvh
Posts: 4
Joined: Mon Dec 31, 2018 11:52 am

Keep table to row reference after shifting rows

Post by paulvvh »

Hi everyone!

I am working on my master thesis on Partner management, and I have come up with an issue.
I have a set of large tables (50*8) that reference eachother. These tables look like an identifier, several properties, and references to another table.


Table 1
X P1 P2 P3 P4 P5 Refers
A .................. 2,6,9
B .................. 2,3,5

Table 2
X P1 P2 P3 P4 P5 Refers
1 .................. B
2 .................. A, B
3 .................. B
4 ..................
5 .................. B
6 .................. A
7 ..................
8 ..................
9 ................... A

Now, these tables are still moldable, and the order of rows might change or I might remove or add rows.

At the moment, the refers column are still 'just' numbers, so if I were to remove Row 1 from table 2, then table 1 would still say that Row A refers to (2,6,9). I would like that the refers column would not list row numbers, but an identifier of a row instead, so I can adapt the row order and still have the correct references. So that when I remove row 1 from table 2, the refers column in of row A changes from (2,6,9) to (1,5,8).

What is a convenient way to do so, and allow row changes in both tables? I have been thinking about a hidden identifier for both tables, but I can't seem to get it to work. Perhaps you guys know an answer.

Thank you for your thoughts!

I am sorry if this question has been asked before, but I was not able to select the right keywords for this question.

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p

Stefan Kottwitz
Site Admin
Posts: 10334
Joined: Mon Mar 10, 2008 9:44 pm

Keep table to row reference after shifting rows

Post by Stefan Kottwitz »

Hi,

welcome to the forum!

Perhaps post some compilable code that we can work on? No real data needed.

Stefan
LaTeX.org admin
paulvvh
Posts: 4
Joined: Mon Dec 31, 2018 11:52 am

Keep table to row reference after shifting rows

Post by paulvvh »

This is a minimal working example, I hope that both final columns can dynamically refer to the other table.
Thanks in advance for your thoughts!

Code: Select all

\documentclass{article}
\usepackage[utf8]{inputenc}
\title{2 tables references}


\begin{document}

\maketitle

\section{Introduction}
\begin{table}[ht!]
\begin{tabular}{p{1cm}p{1,3cm}p{2cm}p{2,5cm}p{1,3cm}p{4cm}}
\hline
\textbf{Value stream ID} & \textbf{Value name} & \textbf{Description} & \textbf{Source} & \textbf{Satisfies} & \textbf{Is provided by instruments} \\ \hline
V1 &&&& G3*, G4*  &  I16*, I35, I53*, I54, I55*
\\  \hline
V2 &&&&  G1, G3, G4  &  I3, I5, I14, I15, I16, I17, I19, I20*, I22, I26, I27, I28, I33, I42, I45, I46*, I49*, I52*, I53
\\ \hline
V3 &&&&  G1, G2, G5  &  I2, I3, I4, I5, I8, I13, I15, I16, I17, I18, I21, I23*, I24, I25, I28, I31*, I32*, I33, I34, I46, I50, I52, I53, I54*, I55*
\\ \hline
V4 &&&&  G2*, G3* &  I5, I6*, I7, I9, I14, I15*, I16*, I17, I18*, I31*, I33, I54*, I55*
\\ \hline
V5 &&&&  G1, G4 & I11, I35, I36*, I39, I39, I41, I42, I43, I44*, I45*, I46, I47*, I49, I50*, I51, I52, I55*
 \\ \hline
V6 &&&& G1*, G2, G3* & I1, I5, I7, I10*, I14, I25, I28, I29*, I31*, I33, I50*
 \\ \hline
V7 &&&&  G2, G4 & I25, I28, I39, I39, I40
 \\ \hline
V8 &&&&  G2, G4 &  I1*, I2*, I3, I4, I6, I11, I15, I19*, I21, I22*, I23, I24, I25, I26*, I27*, I37, I38*, I44, I53*, I54, I55
\\ \hline
V9 &&&&  G1, G2, G5 &  I1, I9, I10, I13*, I14, I18, I20, I21, I23, I30, I32, I33*, I34, I35*, I36*, I44*, I45*, I49*, I50, I51*
\\ \hline
V10 &&&&  G2, G3, G4 &  I1, I10, I11*, I19*, I22*, I26, I27, I29, I30*, I31, I37, I38*, I41*, I42*, I47, I48, I52* \\ \hline
\end{tabular}
\caption{value streams}
\end{table}

\begin{table}
\begin{tabular}{p{2cm}p{1cm}p{2,5cm}p{3,5cm}p{3cm}}
\hline
\textbf{Instrument ID} & \textbf{Partner management area} & \textbf{Instrument name} & \textbf{Sources} & \textbf{Value streams provided} \\ \hline
I1 &&&& V6, V8*, V9, V10 \\ \hline
I2 &&&& V3, V8* \\ \hline
I3 &&&& V2, V3, V8 \\  \hline
I4 &&&& V3, V8 \\ \hline
I5 &&&& V2, V3, V4, V6 \\ \hline
I6 &&&& V4*, V8 \\ \hline
I7 &&&& V4, V6 \\ \hline
I8 &&&& V3, V10 \\ \hline
I9 &&&& V4, V9 \\ \hline
I10 &&&& V6*, V9 \\ \hline
\caption{instruments}
\end{tabular}
\end{table}
\end{document}
User avatar
Stefan Kottwitz
Site Admin
Posts: 10334
Joined: Mon Mar 10, 2008 9:44 pm

Keep table to row reference after shifting rows

Post by Stefan Kottwitz »

Here's quickly a way:

Code: Select all

\usepackage{array}% for column definition
\newcounter{row}[table]
\renewcommand{\therow}{V\arabic{row}}
\newcolumntype{R}{>{\refstepcounter{row}\therow}p{1cm}}
Later use \label and \ref with labels you like. Such as:

Code: Select all

\documentclass{article}
\usepackage[utf8]{inputenc}
\title{2 tables references}
 
\usepackage{array}

\newcounter{row}[table]
\renewcommand{\therow}{V\arabic{row}}
\newcolumntype{R}{>{\refstepcounter{row}\therow}p{1cm}}

 
\begin{document}
 
\maketitle
 
\section{Introduction}
\begin{table}[ht!]
\begin{tabular}{Rp{1,3cm}p{2cm}p{2,5cm}p{1,3cm}p{4cm}}
\hline
\textbf{Value stream ID} & \textbf{Value name} & \textbf{Description} & \textbf{Source} & \textbf{Satisfies} & \textbf{Is provided by instruments} \setcounter{row}{0}\\ \hline

\label{t1} &&&& G3*, G4*  &  I16*, I35, I53*, I54, I55*
\\  \hline
 &&&&  G1, G3, G4  &  I3, I5, I14, I15, I16, I17, I19, I20*, I22, I26, I27, I28, I33, I42, I45, I46*, I49*, I52*, I53
\\ \hline
\label{t2} &&&&  G1, G2, G5  &  I2, I3, I4, I5, I8, I13, I15, I16, I17, I18, I21, I23*, I24, I25, I28, I31*, I32*, I33, I34, I46, I50, I52, I53, I54*, I55*
\\ \hline
 &&&&  G2*, G3* &  I5, I6*, I7, I9, I14, I15*, I16*, I17, I18*, I31*, I33, I54*, I55*
\\ \hline
\label{t3} &&&&  G1, G4 & I11, I35, I36*, I39, I39, I41, I42, I43, I44*, I45*, I46, I47*, I49, I50*, I51, I52, I55*
 \\ \hline
 &&&& G1*, G2, G3* & I1, I5, I7, I10*, I14, I25, I28, I29*, I31*, I33, I50*
 \\ \hline
 &&&&  G2, G4 & I25, I28, I39, I39, I40
 \\ \hline
 &&&&  G2, G4 &  I1*, I2*, I3, I4, I6, I11, I15, I19*, I21, I22*, I23, I24, I25, I26*, I27*, I37, I38*, I44, I53*, I54, I55
\\ \hline
 &&&&  G1, G2, G5 &  I1, I9, I10, I13*, I14, I18, I20, I21, I23, I30, I32, I33*, I34, I35*, I36*, I44*, I45*, I49*, I50, I51*
\\ \hline
 &&&&  G2, G3, G4 &  I1, I10, I11*, I19*, I22*, I26, I27, I29, I30*, I31, I37, I38*, I41*, I42*, I47, I48, I52* \\ \hline
\end{tabular}
\caption{value streams}
\end{table}

See \ref{t1}, \ref{t2}, and \ref{t3}.
\end{document}
LaTeX.org admin
paulvvh
Posts: 4
Joined: Mon Dec 31, 2018 11:52 am

Keep table to row reference after shifting rows

Post by paulvvh »

Thank you very much! I was stuck on this for days, and you provide an elegant solution!

Oh, one more point, how do I prevent my header from being numbered?

Thank you very much!
User avatar
Stefan Kottwitz
Site Admin
Posts: 10334
Joined: Mon Mar 10, 2008 9:44 pm

Keep table to row reference after shifting rows

Post by Stefan Kottwitz »

You can use \multicolumn to get a different formatting for the header cell:

\multicolumn{1}{p{1cm}}{\textbf{Value stream ID}}

By the way, the lines look being very close to the top of the cell content text. Perhaps stretch a bit by \renewcommand{\arraystretch}{1.3} for example, either in the preamble (for all tabulars and arrays) or after \begin{table} for single tables. 1.3 is just a sample.

For better symmetry one could use the booktabs package.

Stefan
LaTeX.org admin
paulvvh
Posts: 4
Joined: Mon Dec 31, 2018 11:52 am

Keep table to row reference after shifting rows

Post by paulvvh »

Wonderful, thank you so much for your time!
Post Reply