我正在尝试为一份报告创建作者表。我希望它看起来像目录,但只包含作者姓名而不是页码。我在网上查找没有成功。有人能给我一些建议吗?
提前致谢!
编辑
以下是我目前所掌握的信息:
\begin{center}
\rowcolors{1}{white}{light-gray}
\begin{tabular}{l r}
Table of Authorship \\ \hline
Section & Author \\
\hline
Introduction & Author \\
\hline
\hspace{1cm} Motivation & Author \\
\hline
\hspace{1cm} Background & Author \\
\hline
\end{tabular}
\end{center}
但正如你们所见,这非常脆弱。如果任何部分发生变化,表格就需要更新。如果能包括各部分的数字就更好了。
编辑2
第二次尝试 MWE:
\documentclass[a4paper]{article}
\usepackage[table]{xcolor}
\usepackage[english]{babel}
\usepackage[utf8x]{inputenc}
\usepackage{amsmath}
\usepackage{graphicx}
\usepackage[colorinlistoftodos]{todonotes}
\usepackage[margin=0.5in]{geometry}
\usepackage{titlesec}
\graphicspath{ {figures/} }
\setcounter{secnumdepth}{4}
\definecolor{light-gray}{gray}{0.95}
\titleformat{\paragraph}
{\normalfont\normalsize\bfseries}{\theparagraph}{1em}{}
\titlespacing*{\paragraph}
{0pt}{3.25ex plus 1ex minus .2ex}{1.5ex plus .2ex}
\title{My MWE}
\author{Robocop}
\begin{document}
\maketitle
\pagebreak
\thispagestyle{empty}
\begin{center}
\rowcolors{1}{white}{light-gray}
\begin{tabular}{l r}
Table of Authorship \\ \hline
Section & Author \\
\hline
Introduction & Author \\
\hline
\hspace{1cm} Motivation & Author \\
\hline
\hspace{1cm} Background & Author \\
\hline
\end{tabular}
\end{center}
\end{document}
答案1
请参阅下面的新版本,其中包含一些改进/解释
这是初次尝试,但还存在一些不足。
.atl
如果进行了更改,则需要删除该文件\subsection
至今未提供等等。
现在,什么在起作用?
我重新定义了该\section
命令以使用[]
包含作者姓名的附加参数。如果为空,则参数值也为空。在此重新定义的\section
命令中,条目被写入外部文件\jobname.atl
(atl 代表作者列表)
为了防止\tableofcontents
写入.atl
过多,我修补了\tableofcontents
使用正常\section
命令。
应该\firsthead
被替换为\endhead
...
\documentclass[a4paper]{article}
\usepackage[table]{xcolor}
\usepackage[english]{babel}
\usepackage[utf8x]{inputenc}
\usepackage{amsmath}
\usepackage{graphicx}
\usepackage{longtable}
\usepackage{xpatch}
\usepackage{blindtext}
\usepackage[colorinlistoftodos]{todonotes}
\usepackage[margin=0.5in]{geometry}
\usepackage{xparse}
\let\LaTeXStandardSection\section
\newwrite\authorfile
\AtBeginDocument{%
\IfFileExists{\jobname.atl}{}{%
\immediate\openout\authorfile=\jobname.atl%
\immediate\write\authorfile{%
\string\rowcolors{1}{white}{light-gray}%
\string\begin{longtable}{rp{0.7\linewidth}l}%
\string& & \unexpanded{\bfseries} Author \tabularnewline%
\string\endfirsthead%
\string\hline^^J%
}%
}%
}
\NewDocumentCommand{\listofauthorships}{}{%
\IfFileExists{\jobname.atl}{%
\LaTeXStandardSection*{TABLE OF AUTHORSHIP}
\begin{center}
\bfseries
\input{\jobname.atl}
\end{center}
}{}%
}
\AtEndDocument{%
\immediate\write\authorfile{% Close the table
\string\end{longtable}%
}%
\immediate\closeout\authorfile% Close the file
}%
\usepackage{titlesec}
\NewDocumentCommand{\WriteATLSectionLine}{smm}
{%
\IfBooleanTF{#1}{\thesection
\immediate\write\authorfile{%
\string \multicolumn{2}{l}{#2} & #3\tabularnewline^^J%
\string\hline%
}%
}{%
\immediate\write\authorfile{%
\thesection \string & #2 & #3\tabularnewline^^J%
\string\hline%
}%
}%
}
\xpatchcmd{\tableofcontents}{\section*}{\LaTeXStandardSection*}{}{}
\RenewDocumentCommand{\section}{somO{}}{%
\IfBooleanTF{#1}{% Test for \section*
\LaTeXStandardSection*{#3}%
\WriteATLSectionLine*{#3}{#4}%
}{%
\IfValueTF{#2}{%
\LaTeXStandardSection[#2]{#3}%
\WriteATLSectionLine{#2}{#4}%
}{%
\LaTeXStandardSection{#3}%
\WriteATLSectionLine{#3}{#4}%
}%
}%
}
\graphicspath{ {figures/} }
\setcounter{secnumdepth}{4}
\definecolor{light-gray}{gray}{0.8}
\titleformat{\paragraph}
{\normalfont\normalsize\bfseries}{\theparagraph}{1em}{}
\titlespacing*{\paragraph}
{0pt}{3.25ex plus 1ex minus .2ex}{1.5ex plus .2ex}
\title{My MWE}
\author{Robocop}
\begin{document}
\tableofcontents
\maketitle
\pagebreak
\thispagestyle{empty}
\listofauthorships
\clearpage
\section*{Abstract}[All of us]
\section{First}[Gandalf]
\blindtext
\section{Second}[Groucho]
\blindtext
\section{Motivation}[Zeppo]
\blindtext
\section[Conclusions]{Conclusions -- finally}[Harpo]
\begin{center}
\rowcolors{1}{white}{light-gray}
\begin{longtable}{l r}
Table of Authorship \\ \hline
Section & Author \\
\hline
Introduction & Author \\
\hline
\hspace{1cm} Motivation & Author \\
\hline
\hspace{1cm} Background & Author \\
\hline
\end{longtable}
\end{center}
\end{document}
改良版
\jobname.atl
更改名称\section...
后删除- 编译三次(对于正确的内容和正确的宽度和内容设置
longtable
)
\documentclass[a4paper]{article}
\usepackage[table]{xcolor}
\usepackage[english]{babel}
\usepackage[utf8x]{inputenc}
\usepackage{amsmath}
\usepackage{graphicx}
\usepackage{longtable}
\usepackage{xpatch}
\usepackage{blindtext}
\usepackage{array}
\usepackage[colorinlistoftodos]{todonotes}
\usepackage[margin=0.5in]{geometry}
\usepackage{titlesec}
\usepackage{xparse}
\newcolumntype{L}[1]{>{\raggedright\arraybackslash}p{#1}} % For quickly changing the column type if needed
\let\LaTeXStandardSection\section
\let\LaTeXStandardSubSection\subsection
\let\LaTeXStandardSubSubSection\subsubsection
\newwrite\authorfile% File handle to write to
\newcommand{\AuthorHeaderName}{\Large Author} % Header name of the table (on the right of the table )
\newlength{\authorcellwidth}
\setlength{\authorcellwidth}{0.15\textwidth} % Space for the author name
\newlength{\contentcellwidth}
\setlength{\contentcellwidth}{0.7\textwidth} % Space for the section names in the table
\AtBeginDocument{%
\IfFileExists{\jobname.atl}{}{%
\immediate\openout\authorfile=\jobname.atl%
\immediate\write\authorfile{%
\string\rowcolors{1}{white}{light-gray}%
\string\begin{longtable}{r@{}l@{}l@{}L{\contentcellwidth}L{\authorcellwidth}}%
\string& & & & \unexpanded{\bfseries \AuthorHeaderName} \tabularnewline%
\string\endhead%
\string\hline^^J%
}%
}%
}
\newcommand{\listofauthorshipsname}{TABLE OF AUTHORSHIP}
% Command for getting the content of the .atl file
\NewDocumentCommand{\listofauthorships}{}{%
\IfFileExists{\jobname.atl}{%
\LaTeXStandardSection*{\listofauthorshipsname}%
\begin{center}%
\bfseries%
\input{\jobname.atl}%
\end{center}%
}{}%
}
\AtEndDocument{%
\immediate\write\authorfile{% Close the table
\string\end{longtable}%
}%
\immediate\closeout\authorfile% Close the file
}%
\NewDocumentCommand{\WriteATLSectionLine}{smm}
{%
\IfBooleanTF{#1}{\thesection
\immediate\write\authorfile{%
\string \multicolumn{4}{l@{}}{#2} & #3\tabularnewline^^J%
\string\hline%
}%
}{%
\immediate\write\authorfile{%
\string\multicolumn{1}{r@{}}{\thesection} \string& \string\multicolumn{3}{l}{#2} & #3\tabularnewline^^J%
\string\hline%
}%
}%
}
\NewDocumentCommand{\WriteATLSubSectionLine}{smm}
{%
\IfBooleanTF{#1}{\thesection
\immediate\write\authorfile{%
\string & \string \multicolumn{3}{l@{}}{#2} & #3\tabularnewline^^J%
\string\hline%
}%
}{%
\immediate\write\authorfile{%
& \string\multicolumn{1}{r@{}}{\thesubsection} \string& \string\multicolumn{2}{l}{#2} & #3\tabularnewline^^J%
\string\hline%
}%
}%
}
\NewDocumentCommand{\WriteATLSubSubSectionLine}{smm}
{%
\IfBooleanTF{#1}{\thesection
\immediate\write\authorfile{%
\string & & \string \multicolumn{2}{l@{}}{#2} & #3\tabularnewline^^J%
\string\hline%
}%
}{%
\immediate\write\authorfile{%
& & \string\multicolumn{1}{r@{}}{\thesubsubsection} \string& \string\multicolumn{1}{l}{#2} & #3\tabularnewline^^J%
\string\hline%
}%
}%
}
%% 'Guaranteeing' the usage of traditional \section stuff, not the redefined ones!
\xpatchcmd{\tableofcontents}{\section*}{\LaTeXStandardSection*}{}{}
\xpatchcmd{\listoffigures}{\section*}{\LaTeXStandardSection*}{}{}
\xpatchcmd{\listoftables}{\section*}{\LaTeXStandardSection*}{}{}
\RenewDocumentCommand{\section}{somO{}}{%
\IfBooleanTF{#1}{% Test for \section*
\LaTeXStandardSection*{#3}%
\WriteATLSectionLine*{#3}{#4}%
}{%
\IfValueTF{#2}{%
\LaTeXStandardSection[#2]{#3}%
\WriteATLSectionLine{#2}{#4}%
}{%
\LaTeXStandardSection{#3}%
\WriteATLSectionLine{#3}{#4}%
}%
}%
}
\RenewDocumentCommand{\subsection}{somO{}}{%
\IfBooleanTF{#1}{% Test for \section*
\LaTeXStandardSubSection*{#3}%
\WriteATLSubSectionLine*{#3}{#4}%
}{%
\IfValueTF{#2}{%
\LaTeXStandardSubSection[#2]{#3}%
\WriteATLSubSectionLine{#2}{#4}%
}{%
\LaTeXStandardSubSection{#3}%
\WriteATLSubSectionLine{#3}{#4}%
}%
}%
}
\RenewDocumentCommand{\subsubsection}{somO{}}{%
\IfBooleanTF{#1}{% Test for \section*
\LaTeXStandardSubSubSection*{#3}%
\WriteATLSubSubSectionLine*{#3}{#4}%
}{%
\IfValueTF{#2}{%
\LaTeXStandardSubSubSection[#2]{#3}%
\WriteATLSubSubSectionLine{#2}{#4}%
}{%
\LaTeXStandardSubSubSection{#3}%
\WriteATLSubSubSectionLine{#3}{#4}%
}%
}%
}
% Other stuff by the OP
\graphicspath{ {figures/} }
\setcounter{secnumdepth}{4}
\definecolor{light-gray}{gray}{0.8}
\titleformat{\paragraph}
{\normalfont\normalsize\bfseries}{\theparagraph}{1em}{}
\titlespacing*{\paragraph}
{0pt}{3.25ex plus 1ex minus .2ex}{1.5ex plus .2ex}
\title{My MWE}
\author{Robocop}
\begin{document}
\tableofcontents
\maketitle
\pagebreak
\thispagestyle{empty}
\listofauthorships
\clearpage
\section*{Abstract}[All of us]
\section{First}[Gummo]
\blindtext
\section{Second}[Groucho]
\subsection{First Subsection}[Chico]
\subsubsection{First SubSubsection}[Groucho]
\subsubsection*{Second SubSubsection}[The 6th Marx Brother]
\blindtext
\section{Motivation}[Zeppo]
\subsection*{Demotivation}[Gummo]
\blindtext
\section[Conclusions]{Conclusions -- finally}[Harpo]
\end{document}
解释:
\let\LaTeXStandardSection\section
抓取 的原始定义\section
并将其存储到\LaTeXStandardSection
—— 这样, 的重新定义\RenewDocumentCommand{\section}
可以使用 的旧行为(无论如何这里都需要)并为其添加额外的功能。和 也是\section
如此。\subsection
\subsubsection
命令参数列表
\section
现在是 {somO{}}, meaning **s**starred ...**o**ptional ... **m**andatory ... **O**ptional, i.e. the starred version of
\section`,然后是 \section[toc-entry]{longer title},然后是新的作者姓名的可选参数,最初设置为空(即 O{})。\RenewDocumentCommand{\section}...
checks if it's a starred section
\section*, using
\WriteATLSectionLine*{#3}{#4}with or
\WriteATLSectionLine{#3}{#4}`,用于控制是否显示章节编号。- 中的代码
\AtBeginDocument
被执行前\begin{document}starts, so this can be used to open the output file for the entries. This is done via
\immediate\openout\authorfile=\jobname.atl。此外,还有一些用于长表 \AtEndDocument` 开头的启动代码is written to the file already, as well the end code stuff in
,其中文件已关闭。 \immediate\write\authorfile{% }
用于将内容写入文件,直接命令必须在前面加上\string, whereas
\thesection`,并且必须在此处扩展,否则它将使用文档的最后一个部分值,而不是相关的部分值。
这是\jobname.atl
\rowcolors{1}{white}{light-gray}
\begin{longtable}{r@{}l@{}l@{}L{\contentcellwidth }L{\authorcellwidth }}
& & & & \bfseries \AuthorHeaderName \tabularnewline
\endhead
\hline
\multicolumn{4}{l@{}}{Abstract} & All of us\tabularnewline
\hline
\multicolumn{1}{r@{}}{1} & \multicolumn{3}{l}{First} & Gummo\tabularnewline
\hline
\multicolumn{1}{r@{}}{2} & \multicolumn{3}{l}{Second} & Groucho\tabularnewline
\hline
& \multicolumn{1}{r@{}}{2.1} & \multicolumn{2}{l}{First Subsection} & Chico\tabularnewline
\hline
& & \multicolumn{1}{r@{}}{2.1.1} & \multicolumn{1}{l}{First SubSubsection} & Groucho\tabularnewline
\hline
& & \multicolumn{2}{l@{}}{Second SubSubsection} & The 6th Marx Brother\tabularnewline
\hline
\multicolumn{1}{r@{}}{3} & \multicolumn{3}{l}{Motivation} & Zeppo\tabularnewline
\hline
& \multicolumn{3}{l@{}}{Demotivation} & Gummo\tabularnewline
\hline
\multicolumn{1}{r@{}}{4} & \multicolumn{3}{l}{Conclusions} & Harpo\tabularnewline
\hline
\end{longtable}