表格行内容,在不同的表格中重复或引用

表格行内容,在不同的表格中重复或引用

任意命名的计数器,引用,回答得非常全面,我有一个后续问题。这个问题很难描述,所以我在互联网和 StackExchange 上搜索可能没有找到任何现有答案,如果是这样,我深表歉意,如果是这样,我很乐意参考以前的答案。

基本上,如果我现在有一张任意标记的漂亮表格(见任意命名的计数器,引用) 因此:

[table begin preamble]
\project{ProjectAlpha} & [Description of alpha.] \\
\project{ProjectBeta}  & [Description of beta.] \\
\project{ProjectGamma} & [Description of gamma.] \\
[end table code]

然后,我需要在文档的其他部分引用整个表格行。即,在文档的其他部分,我可能需要仅使用以下内容显示表格:

[table begin preamble]
ProjectBeta & [Description of beta.] \\
[end table code]

而且我不可能手动重现这一点,因为底层描述会定期变化,所以我希望只编写一次,传播到各处(外部文档也是如此,使用 xr)。

有什么办法吗?也许类似于 \pageref{} 的工作方式,通过显示对象出现的页码,是否可以显示标签所在的整行?

答案1

如果你总是要定义项目及其描述重新使用它,那么您可以使用以下设置:

在此处输入图片描述

\documentclass{article}

\newcommand{\projectnamestyle}[1]{\textsc{#1}}
\newcommand{\projectnamerefstyle}[1]{[\textsc{#1}]}
\newcommand{\projectdescstyle}[1]{\textnormal{#1}}
\newcommand{\projectdescrefstyle}[1]{[\textnormal{#1}]}
\makeatletter
\newcommand{\project}[1]{%
  \projectnamestyle{#1}%
  \global\@namedef{project@name@#1}{\projectnamerefstyle{#1}}%
}
\newcommand{\projectref}[1]{%
  \expandafter\ifx\csname project@name@#1\endcsname\relax
    \textbf{??}%
  \else
    \@nameuse{project@name@#1}%
  \fi}
\newcommand{\projectdesc}[2][\relax]{%
  \projectdescrefstyle{#2}%
  \def\@project{#1}%
  \expandafter\ifx\@project\relax\else
    \expandafter\ifx\csname project@name@#1\endcsname\relax
      \typeout{Project "#1" does not exist.}%
    \else
      \global\@namedef{project@desc@#1}{\projectdescrefstyle{#2}}%
    \fi
  \fi
}
\newcommand{\projectdescref}[1]{%
  \expandafter\ifx\csname project@desc@#1\endcsname\relax
    \textbf{??}%
  \else
    \@nameuse{project@desc@#1}%
  \fi}
\makeatother

\begin{document}
\begin{tabular}{ll}
  \project{Project-Quick}  & \projectdesc[Project-Quick]{Details hereA.}  \\
  \project{Task-Brown}     & \projectdesc[Task-Brown]{Details hereB.}     \\
  \project{Todo-Fox}       & \projectdesc{Details hereC.}                 \\
  \project{Project-Jumped} & \projectdesc[Project-Jumped]{Details hereD.}
\end{tabular}

\projectref{Project-Quick} (description: \projectdescref{Project-Quick}) has been completed \par
\projectref{Task-Brown} (description: \projectdescref{Task-Brown}) has been completed \par
\projectref{Todo-Fox} (description: \projectdescref{Todo-Fox}) is still ongoing \par
\projectref{Project-Jumped} (description: \projectdescref{Project-Jumped}) has been completed
\end{document}

以下内容在项目布局方面提供了更多的自由度zref财产清单:

在此处输入图片描述

\documentclass{article}

\usepackage{zref}% http://ctan.org/pkg/zref

\newcommand{\projectnamerefstyle}[1]{[\textsc{#1}]}
\newcommand{\projectdescrefstyle}[1]{[\textnormal{#1}]}

\makeatletter
\zref@newlist{project}
\zref@newprop{projectname}[\textbf{??}]{-project name-}
\zref@newprop{projectdescription}[\textbf{??}]{-project description-}
\zref@addprops{project}{projectname, projectdescription}
\newcommand{\project}[1]{\zref@setcurrent{projectname}{#1}}%
\newcommand{\projectdesc}[1]{\zref@setcurrent{projectdescription}{#1}}
\newcommand{\projectlabel}[1]{%
  \zref@labelbylist{#1}{project}% Store project information
  \zref@setcurrent{projectname}{\textbf{??}}% Clear project name
  \zref@setcurrent{projectdescription}{\textbf{??}}}% Clear project description
\newcommand{\projectref}[1]{\projectnamerefstyle{\zref@extractdefault{#1}{projectname}{\textbf{??}}}\zref@refused{#1}}
\newcommand{\projectdescref}[1]{\projectdescrefstyle{\zref@extractdefault{#1}{projectdescription}{\textbf{??}}}\zref@refused{#1}}
\makeatother

\begin{document}

\begin{tabular}{ll}
  \projectref{quick}  & \projectdescref{quick} \\
  \projectref{brown}  & \projectdescref{brown} \\
  \projectref{fox}    & \projectdescref{fox}   \\
  \projectref{jumped} & \projectdescref{jumped}
\end{tabular}

\project{Project-Quick} \projectdesc{Details hereA.}\projectlabel{quick}
\project{Task-Brown}    \projectdesc{Details hereB.}\projectlabel{brown}
\project{Todo-Fox}      \projectdesc{Details hereC.}\projectlabel{fox}
\project{Project-Jumped}\projectdesc{Details hereD.}\projectlabel{jumped}

\end{document}

每个项目都使用\project和进行声明\projectdesc。有关这两个属性的信息在您执行 时存储\projectlabel{<label>},并使用\projectref{<label>}和进行调用\projectdescref{<label>}。如果您保留一个包含所有项目的单独文件,这种方法可能会很有用\project{..}\projectdesc{...}\projectlabel{.}

当然,如果需要的话,可以改变界面。

相关内容