TransWikia.com

How to link an enumerate item to a standard list,

TeX - LaTeX Asked on March 17, 2021

I have a list a 4 items that I would like to link it the following results 1) 2) 3) and 4) as shown below.

My MWE

documentclass{article}
usepackage{enumitem}

begin{document}

begin{enumerate}
    item This is item 1. %  this item is linked to --> 1) 
    item This is item 2.  % this item is linked to --> 2) 
    item This is item 3. % this item is linked to --> 3) 
    item This is item 4. % this item is linked to --> 4) 
end{enumerate}

% Results are shown below.

1) xyz  2) abc  3) mno  4) rst 

end{document}

By linking I mean, if I remove item 1 from the list, result 1) xyz will also be removed.
If I move item 3 above item 2 so will result 3) mno move in front of 2) abc so that at all times every item is consistent with the results in terms of relative placement.

I have tried to use the footnote approach to solve this problem, but it was getting out of hand for me and my limited knowledge of LaTeX. I was wondering if there was a way I could ‘tag’ each item and result.

EDIT:

Maybe if I can reword it/simplify the issue.

Suppose I have two lists of n items.

% This is my primary list. I will modify this by moving an item up/down or removing it.

begin{enumerate}
    item This is item 1 in primary list. 
    item This is item 2 in primary list.  
    item This is item 3 in primary list. 
    item This is item 4 in primary list. 
end{enumerate}

% This is my secondary list.


begin{enumerate}
    item This is item 1 in secondary list. 
    item This is item 2 in secondary list.  
    item This is item 3 in secondary list. 
    item This is item 4 in secondary list. 
end{enumerate}

Now if I do the following:

a) shift item 3 from the primary list by up by one, item 3 from the secondary list will also move up by one.
b) remove item 3 from the primary list, item 3 from the secondary list will also be removed.

One Answer

UPDATED ANSWER Can be done without much fuss in lualatex. There are two list to maintain: the name of the Test and the corresponding Result. I think the code is simple to understand.

documentclass[12pt,a4paper]{article}   
usepackage{luacode}
usepackage{xparse}

usepackage{filecontents}% remove in new LaTeX  installations

begin{filecontents*}{"MechTestsi.lua"}
return {
    'Tensile test',
    'Compression test', 
    'Bending test',  
    'Torsion test',  
    'Creep rupture test',  
    'Brinell', 
    'Rockwell',  
    'Vickers',  
    'Impact test',  
    'Wohler fatigue test'
}
end{filecontents*}

begin{filecontents*}{"TestsResultsi.lua"}
return {
    'Te 84–107 Mpa pass',
    'Co 150 Mpam pass', 
    'Be 5000 pass',  
    'To 0.261 pass',  
    'Cr 186 no pass',  
    'Br 1.6 HBS 10/100  no pass', 
    'Ro HRC 55–66 pass',  
    'Vi 140HV30 pass',  
    'Im 3,3  pass',  
    'Wo 62712 no pass'
}
end{filecontents*}

begin{luacode*}
TestMade = {}
local MechTests = require("MechTestsi")
local TestsResults = require("TestsResultsi")

function T(...)
    local sff5=[[item %s  ]]
    local i,j
    
    for j, v in ipairs{...} do
        tex.print(string.format(sff5,  MechTests[v]))
        TestMade[#TestMade+1] =v
    end 
end

function Rx()
    local k
    local sff5=[[item %s]]
    for k =1, #TestMade do
        tex.print(string.format(sff5, TestsResults[TestMade[k]]))       
    end
end
end{luacode*}

NewDocumentCommand{Tests}{O{1} O{nil} O{nil} O{nil} O{nil} O{nil}}{%
directlua{T(#1,#2,#3,#4,#5,#6)}
}   

NewDocumentCommand{LinkedR}{}{directlua{Rx()}}

begin{document}

section{Test completed}

% There are 10 Tests available and 10 correspnding Results
% enter them in the order you like up to 6 at the time or enlarge Tests

begin{enumerate}
    Tests[10]  
    Tests[4][3]
    Tests[6][9][8][1][7]
    Tests[2]
end{enumerate} 

section{Linked Table of results}

% The list of results follows the order of Tests as they where  made. Test #5 (Creep rupture test) was not performed.

begin{enumerate}   
    LinkedR
end{enumerate}

end{document}

output

Correct answer by Simon Dispa on March 17, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP