1

I'm trying to define a custom usecase environment with the ability to typeset paths in the form of lists within a tabularenvironment.

enter image description here

\documentclass{scrartcl}

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

\newcommand{\tabhead}[1]{\textbf{\sffamily#1}}

\newcounter{usecase}
\newenvironment{usecase}[1]{
    \refstepcounter{usecase}
    \begin{center}
    \begin{tabular}[t]{lp{0.8\linewidth}}
    \toprule
    \tabhead{case~\theusecase} & \tabhead{#1}\\
    \midrule
    }
    {\bottomrule\end{tabular}\end{center}}


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

% This doesn't work.
\newenvironment{brokenmainpath}{
    main path & \begin{minipage}{\linewidth}\begin{enumerate}}
    {\end{enumerate}\end{minipage}\\}

% This does.
\newenvironment{mainpath}{
    \begin{minipage}{\linewidth}\begin{enumerate}}
    {\end{enumerate}\end{minipage}}

\begin{document}

% This works.
\begin{usecase}{important use case}
    \actor{actor 1}
    main path & \begin{mainpath}
        \item step 1
        \item step 2
    \end{mainpath}\\
\end{usecase}

% This is what I would like to type to get output in the above image.
%\begin{usecase}{important use case}
%    \actor{actor 1}
%    \begin{mainpath}
%        \item step 1
%        \item step 2
%    \end{mainpath}
%\end{usecase}

\end{document}

The problem is, when I include the main path & into the environment definition (as in brokenmainpath) that should always come in the left column of any use case followed by the steps of the path as an enumerated list in the right column, I get a whole bunch of errors (18 to be precise). They are all of the sort

Extra }, or forgotten \endgroup. \unskip \hfil } \hskip \tabcolsep \endtemplate l.36 \begin{brokenmainpath}

Also, the top alignment of "main path" doesn't seem to be working. Any help would be much appreciated.

  • @Skillmon Ah I see. You're right. I'll remove the update then. – Casimir Jun 4 '17 at 18:29
2

Either you use the answer from the link Salim Bou posted, or you don't use an environment but a command for mainpath (but this way \verb doesn't work):

\documentclass{scrartcl}

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

\newcommand{\tabhead}[1]{\textbf{\sffamily#1}}

\newcounter{usecase}
\newenvironment{usecase}[1]{
    \refstepcounter{usecase}
    \begin{center}
    \begin{tabular}[t]{lp{0.8\linewidth}}
    \toprule
    \tabhead{case~\theusecase} & \tabhead{#1}\\
    \midrule
    }
    {\\\bottomrule\end{tabular}\end{center}}


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

\newcommand\mainpath[1]{%
    main path &\begin{minipage}{\linewidth}\begin{enumerate}%
        #1%
    \end{enumerate}\end{minipage}%
}

\begin{document}
\begin{usecase}{important use case}
    \actor{actor 1}
    \mainpath{%
        \item step 1
        \item step 2
    }
\end{usecase}

\end{document}

Please note that I changed your usecase environment to include the \\ before \bottomrule.

EDIT: For top alignment use \begin{minipage}[t]{<width>}. Below an example using environ and therefore an environment for your problem and with top-alignment.

\documentclass{scrartcl}

\usepackage{booktabs,enumitem}
\usepackage{environ}
\setlist{leftmargin=*,nosep}

\newcommand{\tabhead}[1]{\textbf{\sffamily#1}}

\newcounter{usecase}
\newenvironment{usecase}[1]{
    \refstepcounter{usecase}
    \begin{center}
    \begin{tabular}[t]{lp{0.8\linewidth}}
    \toprule
    \tabhead{case~\theusecase} & \tabhead{#1}\\
    \midrule
    }
    {\\\bottomrule\end{tabular}\end{center}}


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

%\newenvironment{mainpath}{\mainpth}{}
\NewEnviron{mainpath}{%
    \xdef\EnvironmentContents{\unexpanded\expandafter{\BODY}}%
    \gdef\TableRowContents{%
        main path &%
        \begin{minipage}[t]{\linewidth}\begin{enumerate}%
            \EnvironmentContents%
        \end{enumerate}\end{minipage}%
    }%
    \aftergroup\TableRowContents%
}

\begin{document}
\begin{usecase}{important use case}
    \actor{actor 1}
    \begin{mainpath}%
        \item step 1
        \item step 2
    \end{mainpath}
\end{usecase}

\end{document}
  • Thanks for your answer. I knew that a command would work but, syntactically, an environment would be much better here, I think. Any ideas about the top alignment of "main path"? – Casimir Jun 4 '17 at 7:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.