可跨列的自定义用例环境

可跨列的自定义用例环境

我创建了一个自定义环境,将语义与用例表的设计和格式分开。一切正常,只是环境tabularx无法跨列分列,当多个(尤其是较长的)用例紧接着一个时,会产生难看的空白区域。有什么方法可以让它们跨列分列吗?

微波能量吸收 1 微波辐射计 2

\documentclass[10pt]{scrartcl}

\usepackage[english]{babel}
\usepackage[margin=15mm]{geometry}
\usepackage[utf8]{inputenc}
\usepackage[svgnames,table]{xcolor}

\usepackage{booktabs,tabularx,multicol,enumitem,blindtext}
\setlist{leftmargin=*,nosep}

\newcommand{\tabhead}[2][DarkBlue]{\textbf{\large\sffamily\color{#1} #2}}

\newcounter{usecase}
\newenvironment{usecase}[1]{
    \refstepcounter{usecase}
    \noindent\tabularx{\linewidth}{lX}
    \rowcolor{gray!20}\tabhead{Case~\theusecase} & \tabhead[DarkGreen]{#1}\\
    \toprule
    }
    {\bottomrule\endtabularx\medskip}

\newcommand{\actor}[1]{Actor & #1\\\midrule}

\newcommand{\precondition}[1]{Needs & #1\\\midrule}

\newcommand{\mainpath}[1]{
    Path & \begin{minipage}[t]{\linewidth}\blindenumerate[20]
    \end{minipage}\\}

\setlength{\footskip}{1cm}



\begin{document}

\title{The Title}
\author{Casimir}
\date{\today}
\maketitle

\begin{abstract}
    \blindtext
\end{abstract}

\begin{multicols}{2}

\section{First Section}

\blindtext

\subsection{First Subsection}

\begin{usecase}{Some use case}
    \actor{Some actor}
    \precondition{User logged in}
    \mainpath{}
\end{usecase}

\begin{usecase}{Some use case}
    \actor{Some actor}
    \precondition{User logged in}
    \mainpath{}
\end{usecase}

\begin{usecase}{Some use case}
    \actor{Some actor}
    \precondition{User logged in}
    \mainpath{}
\end{usecase}

\begin{usecase}{Some use case}
    \actor{Some actor}
    \precondition{User logged in}
    \mainpath{}
\end{usecase}

\begin{usecase}{Some use case}
    \actor{Some actor}
    \precondition{User logged in}
    \mainpath{}
\end{usecase}

\begin{usecase}{Some use case}
    \actor{Some actor}
    \precondition{User logged in}
    \mainpath{}
\end{usecase}

\end{multicols}

\end{document}

更新

受大卫卡莱尔启发的新实施方式。

\documentclass[10pt]{scrartcl}

\usepackage[english]{babel}
\usepackage[margin=15mm]{geometry}
\usepackage[utf8]{inputenc}
\usepackage[svgnames,table]{xcolor}

\usepackage{multicol,enumitem,blindtext}
\setlist{leftmargin=*,nosep}

\newcommand{\uchead}[2][DarkBlue]{\textbf{\large\sffamily\color{#1} #2}}

\newcounter{usecase}
\newenvironment{usecase}[1]{
    \refstepcounter{usecase}
    \noindent\colorbox{gray!20}{%
       \makebox[\dimexpr\linewidth-2\fboxsep][l]{%
         \uchead{Case~\theusecase}~~\uchead[DarkGreen]{#1}}}\par
    \hrule}
    {\bigskip}

\newlength\lcol\setlength{\lcol}{1.2cm}
\newcommand{\ucentry}[1]{\noindent\strut\makebox[\lcol][l]{\textbf{#1}}}

\newcommand{\actor}[1]{%
    \ucentry{Actor} #1\hrule}

\newcommand{\precondition}[1]{%
    \ucentry{Needs} #1\hrule}

\newcommand{\mainpath}[1]{%
    \ucentry{Path}
    \vspace{-\dimexpr\parskip+\baselineskip}%
    \setlist[enumerate]{labelindent=\dimexpr\lcol+\fboxsep} #1\smallskip\hrule}

\setlength{\footskip}{1cm}



\begin{document}

\title{The Title}
\author{Casimir}
\date{\today}
\maketitle

\begin{abstract}
    \blindtext
\end{abstract}

\begin{multicols}{2}

\section{First Section}

\blindtext

\subsection{First Subsection}

\begin{usecase}{Some use case}
    \actor{Some actor}
    \precondition{User logged in}
    \mainpath{\blindenumerate[9]}
\end{usecase}

\begin{usecase}{Some use case}
    \actor{Some actor}
    \precondition{User logged in}
    \mainpath{\blindenumerate[9]}
\end{usecase}

\begin{usecase}{Some use case}
    \actor{Some actor}
    \precondition{User logged in}
    \mainpath{\blindenumerate[9]}
\end{usecase}

\begin{usecase}{Some use case}
    \actor{Some actor}
    \precondition{User logged in}
    \mainpath{\blindenumerate[9]}
\end{usecase}

\begin{usecase}{Some use case}
    \actor{Some actor}
    \precondition{User logged in}
    \mainpath{\blindenumerate[9]}
\end{usecase}

\begin{usecase}{Some use case}
    \actor{Some actor}
    \precondition{User logged in}
    \mainpath{\blindenumerate[9]}
\end{usecase}

\begin{usecase}{Some use case}
    \actor{Some actor}
    \precondition{User logged in}
    \mainpath{\blindenumerate[9]}
\end{usecase}

\end{multicols}

\end{document}

答案1

看起来像列表的东西通常最好设置为列表而不是表格,然后它们会自然断裂。

你可以对间距进行更多的调整,但是:

在此处输入图片描述

\documentclass[10pt]{scrartcl}

\usepackage[english]{babel}
\usepackage[margin=15mm]{geometry}
\usepackage[utf8]{inputenc}
\usepackage[svgnames,table]{xcolor}

\usepackage{booktabs,tabularx,multicol,enumitem,blindtext}
\setlist{leftmargin=*,nosep}

\newcommand{\tabhead}[2][DarkBlue]{\textbf{\large\sffamily\color{#1} #2}}

\newcounter{usecase}
\newenvironment{usecase}[1]{
    \refstepcounter{usecase}
    \colorbox{gray!20}{%
       \makebox[2cm][l]{\tabhead{Case~\theusecase}}%
       \hspace{6pt}%
       \makebox[\dimexpr\linewidth-3cm-6pt-2\fboxsep]{%
         \tabhead[DarkGreen]{#1}}}\par
    \hrule}
    {\hrule\medskip}

\newcommand{\actor}[1]{%
   \par
   \makebox[2cm][l]{\strut Actor}
       \hspace{6pt}%
   \mbox{#1}\par\hrule}

\newcommand{\precondition}[1]{%
   \par
   \makebox[2cm][l]{\strut Needs}
       \hspace{6pt}%
   \mbox{#1}\par\hrule}


\newcommand{\mainpath}[1]{%
   \par
   \makebox[2cm][l]{\strut Path}
    \par
   \nobreak
   \vspace{-\dimexpr\parskip+\baselineskip}%
    \setlist[enumerate]{leftmargin=2cm}%
   \blindenumerate[20]
  }

\setlength{\footskip}{1cm}



\begin{document}

\title{The Title}
\author{Casimir}
\date{\today}
\maketitle

\begin{abstract}
    \blindtext
\end{abstract}

\begin{multicols}{2}

\section{First Section}

\blindtext

\subsection{First Subsection}

\begin{usecase}{Some use case}
    \actor{Some actor}
    \precondition{User logged in}
    \mainpath{}
\end{usecase}

\begin{usecase}{Some use case}
    \actor{Some actor}
    \precondition{User logged in}
    \mainpath{}
\end{usecase}

\begin{usecase}{Some use case}
    \actor{Some actor}
    \precondition{User logged in}
    \mainpath{}
\end{usecase}

\begin{usecase}{Some use case}
    \actor{Some actor}
    \precondition{User logged in}
    \mainpath{}
\end{usecase}

\begin{usecase}{Some use case}
    \actor{Some actor}
    \precondition{User logged in}
    \mainpath{}
\end{usecase}

\begin{usecase}{Some use case}
    \actor{Some actor}
    \precondition{User logged in}
    \mainpath{}
\end{usecase}

\end{multicols}

\end{document}

相关内容