我有一个包含 4 项的列表,我想将其链接到以下结果 1) 2) 3) 和 4),如下所示。
我的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}
我所说的链接是指,如果我从列表中删除 \item 1,结果 1) xyz 也将被删除。如果我将 \item 3 移到 \item 2 上方,那么结果 3) mno 将移到 2) abc 前面,这样在任何时候,每个 \item 在相对位置方面都与结果一致。
我曾尝试使用脚注方法解决这个问题,但对于我和我对 LaTeX 的了解有限的人来说,这种方法无法控制。我想知道是否有办法“标记”每个项目和结果。
编辑:
也许我可以重新措辞/简化这个问题。
假设我有两个列表n项目。
% 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}
现在如果我执行以下操作:
a) 将主列表中的项目 3 上移一位,辅助列表中的项目 3 也将上移一位。b) 从主列表中删除项目 3,辅助列表中的项目 3 也将被删除。
答案1
更新答案 在lualatex中可以毫不费力地完成。需要维护两个列表:测试的名称和相应的结果。我认为代码简单易懂。
\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}