如何才能制作编辑列表/表格?
我并不是在问如何创建列表或表格,而是问是否可以将某些内容以或类似的形式附加到\section
's 和's 上,以便能够生成以下内容:\subsection
\label
+-----------+-------------+-------------+---------+
| Section | Subsection | Responsible | Helpers |
+-----------+-------------+-------------+---------+
| Section 1 | | Bob | |
| Section 2 | | | |
| | Section 2.1 | Jimmy | |
| | Section 2.2 | Carl | |
| Section 3 | | Bob | Carl |
| | Section 3.1 | Jimmy | Bob |
| Section 4 | | Everybody | |
+-----------+-------------+-------------+---------+
所以基本上可以使用一些东西\foreach
\section
并\subsection
生成如上所示的表格。然后添加信息以及各部分。
粗略的例子:
\section{Section 1}{Bob}{}
\section{Section 2}{}{}
\section{Section 3}{Bob}{Carl}
\subsection{Section 3.1}{Jimmy}{Bob}
另外,这是否是一种糟糕的解决问题的方法?如果是的话,有没有更好的方法?
答案1
这是一个解决方案
\documentclass{article}
\usepackage{lipsum}
\newcommand*\editorialtable{%
\beforeeditorialtable
\begin{tabular}{|l|l|l|l|}
\hline
\multicolumn{1}{|c}{Section} & \multicolumn{1}{|c}{Subsection} &
\multicolumn{1}{|c}{Responsible}&\multicolumn{1}{|c|}{Helpers}\\
\hline
\makeeditorialtable
\end{tabular}
\aftereditorialtable}
\newcommand*\beforeeditorialtable{\par}
\newcommand*\aftereditorialtable{\par}
\newcommand*\makeeditorialtable{}
\makeatletter
\newcommand{\mtsection}[3]{%
\section{#1}
\addtocontents{toc}{\protect\g@addto@macro\protect\makeeditorialtable{#1&\\\protect\hline}}}
\newcommand{\mtsubsection}[3]{%
\subsection{#1}
\addtocontents{toc}{\protect\g@addto@macro\protect\makeeditorialtable{\\\protect\hline}}}
\makeatother
\begin{document}
\tableofcontents % necessary
\editorialtable
\mtsection{Section 1}{Bob}{}
\mtsection{Section 2}{}{}
\mtsection{Section 3}{Bob}{Carl}
\mtsubsection{Section 3.1}{Jimmy}{Bob}
\editorialtable
\end{document}
答案2
请参阅最后的更新和更好的版本!
expl3
具有功能和键值接口的初步版本,目前仅适用于末尾的表格!
\documentclass{article}
\usepackage{xparse}
\usepackage{xkeyval}
\makeatletter
\let\latex@@section\section
\let\latex@@subsection\subsection
\define@key{editorial}{helper}{%
\def\kveditorial@helper{#1}%
}
\define@key{editorial}{responsible}{%
\def\kveditorial@responsible{#1}
}
\ExplSyntaxOn
\seq_new:N \g_vallentin_editorial_seq
\NewDocumentCommand{\EditorialBoard}{}{%
\begin{tabular}{*{4}{p{3cm}}}
\bfseries Section & \bfseries subsection & \bfseries Responsible & \bfseries Helper \tabularnewline
\hline
\seq_use:Nn \g_vallentin_editorial_seq {\tabularnewline}
\end{tabular}
}
\RenewDocumentCommand{\section}{somo}{%
\IfBooleanTF{#1}{%
\latex@@section*{#3}%
}{%
\IfValueTF{#2}{%
\latex@@section[#2]{#3}%
}{%
\latex@@section{#3}%
}%
\IfValueTF{#4}{%
\typeout{Some value:#4}
\setkeys{editorial}{#4}%
\seq_gput_right:Nx \g_vallentin_editorial_seq {#3\space\thesection & & \kveditorial@responsible & \kveditorial@helper}%
}{%
\typeout{No value:#4}
\seq_gput_right:Nn \g_vallentin_editorial_seq {#3}
}
}%
}
\RenewDocumentCommand{\subsection}{somo}{%
\IfBooleanTF{#1}{%
\latex@@subsection*{#3}%
}{%
\IfValueTF{#2}{%
\latex@@subsection[#2]{#3}%
}{%
\latex@@subsection{#3}%
}%
\IfValueTF{#4}{%
\setkeys{editorial}{#4}%
\seq_gput_right:Nx \g_vallentin_editorial_seq {& #3\space\thesubsection & \kveditorial@responsible & \kveditorial@helper}%
}{%
\seq_gput_right:Nn \g_vallentin_editorial_seq {& #3}
}
}%
}
\ExplSyntaxOff
\makeatother
\begin{document}
\tableofcontents
\section{Foo}[helper=Harpo,responsible=Chico]
\section{Foo bar}[helper=Gummo,responsible=Groucho]
\section{Other foo bar}
\subsection{Some subsection}[helper={some blokes from TeX.SX},responsible=You!]
\EditorialBoard
\end{document}
更新
此版本允许放置EditorialBoard
在文档主体的任何位置。内容始终存储在文档末尾并在\EditorialBoard
使用时读取。
文件名称为\jobname.edo
。
\documentclass{article}
\usepackage{booktabs}
\usepackage{xparse}
\usepackage{xkeyval}
\makeatletter
\let\latex@@section\section
\let\latex@@subsection\subsection
% Define two keys
\define@key{editorial}{helper}{%
\def\kveditorial@helper{#1}%
}
\define@key{editorial}{responsible}{%
\def\kveditorial@responsible{#1}
}
\newcommand{\editorialboardname}{Editorial Board}
\ExplSyntaxOn
\seq_new:N \g_vallentin_editorial_seq % Holding the content
\iow_new:N \g_vallentin_editorial_outfile
\ior_new:N \g_vallentin_editorial_infile
\cs_new:Nn \vallentin_store_editorial_content:n {%
\iow_open:Nn \g_vallentin_editorial_outfile {#1}
\seq_map_inline:Nn \g_vallentin_editorial_seq {%
\iow_now:Nn \g_vallentin_editorial_outfile {##1}
}
\iow_close:N \g_vallentin_editorial_outfile % Close the file
}
\NewDocumentCommand{\StoreEditorialContent}{m}{%
\vallentin_store_editorial_content:n{#1}
}
\cs_new:Nn \read_from_external_file:n{%
% Only add the content if it's not already there!
\seq_if_in:NnF \g_vallentin_editorial_seq {#1}{%
\seq_gput_right:Nn \g_vallentin_editorial_seq {#1}
}
}
\cs_new:Nn \grab_old_editorial_file:n{%
\seq_gclear:N \g_vallentin_editorial_seq
\ior_open:Nn \g_vallentin_editorial_infile {#1}
\ior_map_inline:Nn \g_vallentin_editorial_infile {\read_from_external_file:n{##1}}%
\ior_close:N \g_vallentin_editorial_infile
}
\NewDocumentCommand{\ReadEditorialContent}{m}{%
\IfFileExists{#1}{%
\section*{\editorialboardname}
\grab_old_editorial_file:n {#1}
}{}
}
\NewDocumentCommand{\displayeditorialline}{}{%
\seq_use:Nn \g_vallentin_editorial_seq {\tabularnewline\midrule} % Display all in a row!
}
\NewDocumentCommand{\AddSectionEditorialLine}{m}{%
\seq_gput_right:Nx \g_vallentin_editorial_seq {#1}
}
\ExplSyntaxOff
% Redefine the section commands -- does not work for memoir.cls!
\RenewDocumentCommand{\section}{somo}{%
\IfBooleanTF{#1}{%
\latex@@section*{#3}%
}{%
\IfValueTF{#2}{%
\latex@@section[#2]{#3}%
}{%
\latex@@section{#3}%
}%
\IfValueTF{#4}{%
\setkeys{editorial}{#4}%
\AddSectionEditorialLine{#3 \thesection & & \kveditorial@responsible & \kveditorial@helper}%
}{%
\AddSectionEditorialLine{#3}
}
}%
}
\RenewDocumentCommand{\subsection}{somo}{%
\IfBooleanTF{#1}{%
\latex@@subsection*{#3}%
}{%
\IfValueTF{#2}{%
\latex@@subsection[#2]{#3}%
}{%
\latex@@subsection{#3}%
}%
\IfValueTF{#4}{%
\setkeys{editorial}{#4}%
\AddSectionEditorialLine{& #3 \thesubsection & \kveditorial@responsible & \kveditorial@helper}%
}{%
\AddSectionEditorialLine{& #3}%
}%
}%
}
\makeatother
\AtEndDocument{%
\StoreEditorialContent{\jobname.edo}%
}
\NewDocumentCommand{\EditorialBoard}{O{\jobname.edo}}{%
\clearpage
\ReadEditorialContent{#1}%
\begin{tabular}{*{4}{p{3cm}}}
\bfseries Section & \bfseries Subsection & \bfseries Responsible & \bfseries Helper \tabularnewline
\toprule
\displayeditorialline%
\end{tabular}
}
\begin{document}
\tableofcontents
\EditorialBoard
\section{Foo}[helper=Harpo,responsible=Chico]
\section{Foo bar}[helper=Gummo,responsible=Groucho]
\section{Other foo bar}
\subsection{Some subsection}[helper={some blokes from TeX.SX},responsible=You!]
\subsection{Other stuff}[helper={Ann Elk},responsible={Arthur Gumby}]
\section{A new section}[responsible={Gandalf},helper={Frodo}]
\end{document}