LaTeX forum ⇒ Graphics, Figures & TablesKeep table to row reference after shifting rows Topic is solved

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

Keep table to row reference after shifting rows

Postby paulvvh » Mon Dec 31, 2018 12:11 pm

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.

User avatar
Stefan Kottwitz
Site Admin
Posts: 9244
Joined: Mon Mar 10, 2008 9:44 pm

Postby Stefan Kottwitz » Mon Dec 31, 2018 5:18 pm

Hi,

welcome to the forum!

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

Stefan
Site admin

paulvvh
Posts: 4
Joined: Mon Dec 31, 2018 11:52 am

Postby paulvvh » Wed Jan 02, 2019 10:54 am

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!

  1. \documentclass{article}
  2. \usepackage[utf8]{inputenc}
  3. \title{2 tables references}
  4.  
  5.  
  6. \begin{document}
  7.  
  8. \maketitle
  9.  
  10. \section{Introduction}
  11. \begin{table}[ht!]
  12. \begin{tabular}{p{1cm}p{1,3cm}p{2cm}p{2,5cm}p{1,3cm}p{4cm}}
  13. \hline
  14. \textbf{Value stream ID} & \textbf{Value name} & \textbf{Description} & \textbf{Source} & \textbf{Satisfies} & \textbf{Is provided by instruments} \\ \hline
  15. V1 &&&& G3*, G4* & I16*, I35, I53*, I54, I55*
  16. \\ \hline
  17. V2 &&&& G1, G3, G4 & I3, I5, I14, I15, I16, I17, I19, I20*, I22, I26, I27, I28, I33, I42, I45, I46*, I49*, I52*, I53
  18. \\ \hline
  19. 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*
  20. \\ \hline
  21. V4 &&&& G2*, G3* & I5, I6*, I7, I9, I14, I15*, I16*, I17, I18*, I31*, I33, I54*, I55*
  22. \\ \hline
  23. V5 &&&& G1, G4 & I11, I35, I36*, I39, I39, I41, I42, I43, I44*, I45*, I46, I47*, I49, I50*, I51, I52, I55*
  24. \\ \hline
  25. V6 &&&& G1*, G2, G3* & I1, I5, I7, I10*, I14, I25, I28, I29*, I31*, I33, I50*
  26. \\ \hline
  27. V7 &&&& G2, G4 & I25, I28, I39, I39, I40
  28. \\ \hline
  29. V8 &&&& G2, G4 & I1*, I2*, I3, I4, I6, I11, I15, I19*, I21, I22*, I23, I24, I25, I26*, I27*, I37, I38*, I44, I53*, I54, I55
  30. \\ \hline
  31. V9 &&&& G1, G2, G5 & I1, I9, I10, I13*, I14, I18, I20, I21, I23, I30, I32, I33*, I34, I35*, I36*, I44*, I45*, I49*, I50, I51*
  32. \\ \hline
  33. V10 &&&& G2, G3, G4 & I1, I10, I11*, I19*, I22*, I26, I27, I29, I30*, I31, I37, I38*, I41*, I42*, I47, I48, I52* \\ \hline
  34. \end{tabular}
  35. \caption{value streams}
  36. \end{table}
  37.  
  38. \begin{table}
  39. \begin{tabular}{p{2cm}p{1cm}p{2,5cm}p{3,5cm}p{3cm}}
  40. \hline
  41. \textbf{Instrument ID} & \textbf{Partner management area} & \textbf{Instrument name} & \textbf{Sources} & \textbf{Value streams provided} \\ \hline
  42. I1 &&&& V6, V8*, V9, V10 \\ \hline
  43. I2 &&&& V3, V8* \\ \hline
  44. I3 &&&& V2, V3, V8 \\ \hline
  45. I4 &&&& V3, V8 \\ \hline
  46. I5 &&&& V2, V3, V4, V6 \\ \hline
  47. I6 &&&& V4*, V8 \\ \hline
  48. I7 &&&& V4, V6 \\ \hline
  49. I8 &&&& V3, V10 \\ \hline
  50. I9 &&&& V4, V9 \\ \hline
  51. I10 &&&& V6*, V9 \\ \hline
  52. \caption{instruments}
  53. \end{tabular}
  54. \end{table}
  55. \end{document}

User avatar
Stefan Kottwitz
Site Admin
Posts: 9244
Joined: Mon Mar 10, 2008 9:44 pm

Postby Stefan Kottwitz » Wed Jan 02, 2019 2:12 pm

Here's quickly a way:

  1. \usepackage{array}% for column definition
  2. \newcounter{row}[table]
  3. \renewcommand{\therow}{V\arabic{row}}
  4. \newcolumntype{R}{>{\refstepcounter{row}\therow}p{1cm}}


Later use \label and \ref with labels you like. Such as:

  1. \documentclass{article}
  2. \usepackage[utf8]{inputenc}
  3. \title{2 tables references}
  4.  
  5. \usepackage{array}
  6.  
  7. \newcounter{row}[table]
  8. \renewcommand{\therow}{V\arabic{row}}
  9. \newcolumntype{R}{>{\refstepcounter{row}\therow}p{1cm}}
  10.  
  11.  
  12. \begin{document}
  13.  
  14. \maketitle
  15.  
  16. \section{Introduction}
  17. \begin{table}[ht!]
  18. \begin{tabular}{Rp{1,3cm}p{2cm}p{2,5cm}p{1,3cm}p{4cm}}
  19. \hline
  20. \textbf{Value stream ID} & \textbf{Value name} & \textbf{Description} & \textbf{Source} & \textbf{Satisfies} & \textbf{Is provided by instruments} \setcounter{row}{0}\\ \hline
  21.  
  22. \label{t1} &&&& G3*, G4* & I16*, I35, I53*, I54, I55*
  23. \\ \hline
  24. &&&& G1, G3, G4 & I3, I5, I14, I15, I16, I17, I19, I20*, I22, I26, I27, I28, I33, I42, I45, I46*, I49*, I52*, I53
  25. \\ \hline
  26. \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*
  27. \\ \hline
  28. &&&& G2*, G3* & I5, I6*, I7, I9, I14, I15*, I16*, I17, I18*, I31*, I33, I54*, I55*
  29. \\ \hline
  30. \label{t3} &&&& G1, G4 & I11, I35, I36*, I39, I39, I41, I42, I43, I44*, I45*, I46, I47*, I49, I50*, I51, I52, I55*
  31. \\ \hline
  32. &&&& G1*, G2, G3* & I1, I5, I7, I10*, I14, I25, I28, I29*, I31*, I33, I50*
  33. \\ \hline
  34. &&&& G2, G4 & I25, I28, I39, I39, I40
  35. \\ \hline
  36. &&&& G2, G4 & I1*, I2*, I3, I4, I6, I11, I15, I19*, I21, I22*, I23, I24, I25, I26*, I27*, I37, I38*, I44, I53*, I54, I55
  37. \\ \hline
  38. &&&& G1, G2, G5 & I1, I9, I10, I13*, I14, I18, I20, I21, I23, I30, I32, I33*, I34, I35*, I36*, I44*, I45*, I49*, I50, I51*
  39. \\ \hline
  40. &&&& G2, G3, G4 & I1, I10, I11*, I19*, I22*, I26, I27, I29, I30*, I31, I37, I38*, I41*, I42*, I47, I48, I52* \\ \hline
  41. \end{tabular}
  42. \caption{value streams}
  43. \end{table}
  44.  
  45. See \ref{t1}, \ref{t2}, and \ref{t3}.
  46. \end{document}
Site admin

paulvvh
Posts: 4
Joined: Mon Dec 31, 2018 11:52 am

Postby paulvvh » Wed Jan 02, 2019 2:49 pm

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: 9244
Joined: Mon Mar 10, 2008 9:44 pm

Postby Stefan Kottwitz » Wed Jan 02, 2019 3:38 pm

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
Site admin

paulvvh
Posts: 4
Joined: Mon Dec 31, 2018 11:52 am

Postby paulvvh » Thu Jan 03, 2019 11:52 am

Wonderful, thank you so much for your time!


Return to “Graphics, Figures & Tables”

Who is online

Users browsing this forum: No registered users and 7 guests