我想要做什么
我想创建一个表格,以清晰的方式呈现大量变量。每个类都有自己的表格,其中包含最多一百个变量,因此表格必须能够跨越多页。
我的问题是什么
- 我没有一个干净的方法来在多列中创建列表(图片中的最后一个标题)并将此列表移至相应的标题下。标题下的变量组不再适合表格的标题,但属于此类,所以我不想为它们创建新表格。也许我会为这一部分添加自定义标题?
- 另外:有时,最后一列无法容纳较大的字符串或长值。我实施的解决方案\长值相当混乱。而且我在不同层级缩进变量和标题的方式似乎过于复杂。
由于我对 LaTeX 还很陌生,因此我将非常感谢您关于布局的每一条提示或建议。
\documentclass{scrbook}
\usepackage{array}
\usepackage{booktabs}
\usepackage{longtable}
\usepackage{enumitem}
% -------------------------- Table Layering Commands ------------------------- %
\newcommand{\varlone}[3]{\MakeUppercase{\ttfamily #1} & #2 & \ttfamily{#3} \\}
\newcommand{\caplone}[1]{\addlinespace[0.5em]\multicolumn{3}{l}{#1} \\ \cmidrule(l{.5em}){1-3}}
\newcommand{\varltwo}[3]{\enspace\MakeUppercase{\ttfamily #1} & #2 & \ttfamily{#3} \\}
\newcommand{\capltwo}[1]{\addlinespace[0.5em]\multicolumn{3}{>{\enspace}l}{#1} \\ \cmidrule(l{1em}){1-3}}
\newcommand{\varlthree}[3]{\quad\MakeUppercase{\ttfamily #1} & #2 & \ttfamily{#3} \\}
% --------------------------- Variable Description --------------------------- %
\newlist{optList}{enumerate}{1}
\setlist[optList]{nosep,label={},left=0.5em}
\newenvironment{varopts}{\begin{optList}\footnotesize}{\end{optList}\vspace*{-\baselineskip}\leavevmode}
\newcommand{\longvalue}[2][5cm]{\makebox[0em][r]{\parbox[t]{#1}{\raggedleft #2}}}
\newcommand{\arraysize}[1]{(Array (#1))}
% ------------------------------ Ugly hardcoded ------------------------------ %
\newcommand{\sensors}[2]{\multicolumn{3}{l}{\quad #1 \enspace {\ttfamily{#2}}} \\}
% ----------------------------- Table Environment ---------------------------- %
\newenvironment{classtable}[2]{\begin{longtable}{l p{0.63\linewidth} r}
\caption{class = \MakeUppercase{#1}}\label{tab:class_#1}\\
\toprule
\multicolumn{3}{@{}p{\linewidth}@{}}{#2}\\
\midrule
Name & Description & Value \\
\midrule
\endfirsthead
\midrule
Name & Description & Value \\
\midrule
\endhead}{\bottomrule\end{longtable}}
% ---------------------------------------------------------------------------- %
\begin{document}
\begin{classtable}{classname}{A short description of the contents of the class spanning multiple rows. This table has to feature a lot of variables and might span multiple pages.}
%
\caplone{A caption on layer one}
\varltwo{var1}{This is the first variable}{\longvalue{long string value\\with linebreak}}
\varltwo{testvar}{Variable on layer two with arraysize \arraysize{2}}{1.5,4.0}
%
\capltwo{A caption on layer two}
\varlthree{var3}{Variable on layer three with description \begin{varopts}
\item 1 = Description of first option
\item 2 = Description of second option
\end{varopts}}{2}
\varlthree{var4}{Variable on layer three}{test}
%
\varlone{var5}{Standalone variable on layer one}{3}
\capltwo{List variable options in a caption
\quad\makebox[0em][t]{\parbox[t]{15cm}{\footnotesize
{\ttfamily{-X}} (0 = off, 1 = on) Enables something \\
{\ttfamily{-XX}} (1 = none, 2 = few) Calculates something}}}
\sensors{One type with a long name}{sen1X = 1, sen1XX = 1}
\sensors{Another type}{sen2X = 0, sen2XX = 2}
\end{classtable}
\end{document}