表格行号参考

表格行号参考

我的一个学生需要做采访工作。她有一堆受访者的回答,需要打印成完整的引文。她的工作是分析这些答案并给出某种总结。因此,答案应该有行号,以便她参考。

我尝试启用包lineno,但无法使标签在表格中工作。

正如您所看到的,我设法在引用的答案上打印行号并将其关闭以进行分析。

更新了 MWE,以在表格中显示多行排版文本

\documentclass[%
   a4paper,
   11pt,
   twoside,
   parskip=half,
   english,
]{scrartcl}

%%% ------------------------------------------------------ &Packages ---
\usepackage{babel}                      % Language selection
\usepackage[T1]{fontenc}                % Output font encoding
\usepackage[newcommands]{ragged2e}      % Hyphenation in ragged modes
\usepackage[running]{lineno}            % Package for line numbers
\usepackage{array}                      % Improved tabular macros
\usepackage{xltabular}                  % X-Column and longtables altogether 
\usepackage{booktabs}                   % Nicer table lines

  

%%% --------------------------------------------------- &Definitions ---
%%% Some useful definitions . . .

%% Neuer Spaltentyp L für linksbündigen Flattersatz mit variabler
%% Breite (#1).  
\newcolumntype{L}[1]{ >{\nolinenumbers\raggedright\hspace{0pt}\arraybackslash} p{#1} }

%% Und noch mal, aber auf Basis der X-Spalte
\newcolumntype{Y}{
  >{\internallinenumbers\raggedright\hspace{0pt}\arraybackslash}
  X
  <{\nolinenumbers}
}

%% Und eine Definition für die Spaltenüberschriften
\newcolumntype{H}{ >{\footnotesize} c }


%% Neues Makro mit dem die Antwort eingegeben wird.
\newcommand{\answer}[1]{%
    \begin{linenumbers}%
      % \begin{numquote}%
      #1%
      % \end{numquote}%
    \end{linenumbers}%
}

%% Und zwei Befehle, um die referenzierte Zeilennummer zu markieren
%% bzw. zu referenzieren.
\newcommand{\imark}[1]{\linelabel{answer:#1}}
\newcommand{\iref}[1]{line~\ref{answer:#1}}
\newcommand{\iregion}[2]{%
  Zeilen~\ref{answer:#1}--\ref{answer:#2}%
}




%%% ====================================================== &Document ===
\begin{document}

%% This works
\begin{linenumbers}
  The sun\imark{sun} was shining the whole day.
\end{linenumbers}
In \iref{sun} she speaks of weather.

%% This works also
\answer{The sun didn't shine for month.  It was dark\imark{dark} and
  cold.}
In \iref{dark} temperatures are mentioned.

\begin{tabularx}{\linewidth}{@{} Y L{.3\textwidth} @{}}
  \toprule
  \multicolumn{1}{@{} H}{Answer}
  & \multicolumn{1}{H @{}}{Explanation} \\
  \midrule
  %% Numbers printed, reference undefined, no error messages
  \answer{The sun\imark{sun2} was shining the whole day.  
  But from time\iref{time} to time, it also rained, which poduced 
  beautiful rainbows\ilabel{rainbow} in the otherwise clear blue
  sky.\ilabel{sky}}
  & In \iref{sun2} she speaks of weather.\newline
    In \iregion{time}{sky} something other is discussed.\\
  % %% Error message: "\linelabel without \linenumbers".
  % The sun\imark{sun3} was shining the whole day.
  % & In \iref{sun3} she speaks of weather.\\
  \bottomrule
\end{tabularx}

\end{document}

存储/检索表格中的行号的技巧是什么?

答案1

那么用 来耍什么肮脏的花招呢paracol

\documentclass[%
   a4paper,
   11pt,
   twoside,
   parskip=half,
   english,
]{scrartcl}
\usepackage{showframe}
%%% ------------------------------------------------------ &Packages ---
\usepackage{babel}                      % Language selection
\usepackage[T1]{fontenc}                % Output font encoding
\usepackage[newcommands]{ragged2e}      % Hyphenation in ragged modes
\usepackage[running]{lineno}            % Package for line numbers
\usepackage{array}                      % Improved tabular macros
\usepackage{xltabular}                  % X-Column and longtables altogether 
\usepackage{booktabs}                   % Nicer table lines
\usepackage{paracol}
\columnratio{0.7}
  

%%% --------------------------------------------------- &Definitions ---
%%% Some useful definitions . . .

%% Neuer Spaltentyp L für linksbündigen Flattersatz mit variabler
%% Breite (#1).  
\newcolumntype{L}[1]{ >{\nolinenumbers\raggedright\hspace{0pt}\arraybackslash} p{#1} }

%% Und noch mal, aber auf Basis der X-Spalte
\newcolumntype{Y}{
  >{\internallinenumbers\raggedright\hspace{0pt}\arraybackslash}
  X
  <{\nolinenumbers}
}

%% Und eine Definition für die Spaltenüberschriften
\newcolumntype{H}{ >{\footnotesize} c }


%% Neues Makro mit dem die Antwort eingegeben wird.
\newcommand{\answer}[1]{%
    \begin{linenumbers}%
      % \begin{numquote}%
      #1%
      % \end{numquote}%
    \end{linenumbers}%
}

%% Und zwei Befehle, um die referenzierte Zeilennummer zu markieren
%% bzw. zu referenzieren.
\newcommand{\imark}[1]{\linelabel{answer:#1}}
\newcommand{\iref}[1]{line~\ref{answer:#1}}
\newcommand{\iregion}[2]{%
  Zeilen~\ref{answer:#1}--\ref{answer:#2}%
}




%%% ====================================================== &Document ===
\begin{document}

%% This works
\begin{linenumbers}
  The sun\imark{sun} was shining the whole day.
\end{linenumbers}
In \iref{sun} she speaks of weather.

%% This works also
\answer{The sun didn't shine for month.  It was dark\imark{dark} and
  cold.}
In \iref{dark} temperatures are mentioned.

\begin{tabularx}{\linewidth}{@{}>{\footnotesize\centering\arraybackslash}p{.7\linewidth} >{\footnotesize\centering\arraybackslash}X@{}}
  \toprule
  Answer
  & Explanation \\
  \midrule
\end{tabularx}
\begin{sloppypar}
\begin{paracol}{2} 
  \answer{The sun\imark{sun2} was shining the whole day.  
  But from time\imark{time} to time, it also rained, which produced 
  beautiful rainbows\imark{rainbow} in the otherwise clear blue
  sky.\imark{sky}}
  \switchcolumn
  In sun: \iref{sun2} she speaks of weather.\newline
  Rainbows: \iref{rainbow}.\newline
  In time: \iref{time}, sky: \iref{sky} something other is discussed.
\end{paracol}
\begin{paracol}{2} 
  \answer{The sun\imark{sun3} was shining the whole day.  
  But from time\imark{time3} to time, it also rained, which produced 
  beautiful rainbows\imark{rainbow3} in the otherwise clear blue
  sky.\imark{sky3}}
  \switchcolumn
  In sun: \iref{sun3} she speaks of weather.\newline
  Rainbows: \iref{rainbow3}.\newline
  In time: \iref{time3}, sky: \iref{sky3} something other is discussed.
\end{paracol}
\end{sloppypar}\vspace{-8pt}
\begin{tabularx}{\linewidth}{@{}X@{}}
  \bottomrule
\end{tabularx}

\end{document}

在此处输入图片描述

相关内容