如何製作特殊的「或」環境?

如何製作特殊的「或」環境?

我想建立一個由左側的垂直線和在每個換行符處插入的自動“或”組成的環境。它的目的是在數學背景下。

它看起來像這樣:

模型

答案1

您可以使用該tcolorbox套件建立一個建立垂直線的環境。

\documentclass[a4paper]{article}
\usepackage[most]{tcolorbox}
% \usepackage{pgfplots}


\newtcolorbox{env}{
        enhanced,
        breakable, % This make the box breakable
        boxrule=0pt,
        frame hidden,
        borderline west={2pt}{0pt}{black}, % this create the line
        colback=white, % The background color,
        math upper,
        hbox,
        center
    }

\begin{document}
 Text text text
    \begin{env}
        \int_{-\infty}^{\infty}f(x)\delta(x-a)dx = f(a)
    \end{env}

\end{document}

在此輸入影像描述

答案2

您可以使用類似數組的環境並添加或者在每個不是第一個的元素之前,不是很乾淨,但它可以工作。

    \documentclass[a4paper]{article}

    \usepackage{ifthen}
    \newcounter{orcounter}

    \newenvironment{orlist}{%
      \noindent\begin{tabular*}{\textwidth}{|l}
      \setcounter{orcounter}{0}
    }{%
     \end{tabular*}
    }

    \newcommand{\oritem}[1]{%
      \ifthenelse{\equal{\theorcounter}{0}}{\hspace{-1em}}{\\ \textbf{or}\\}
      #1\stepcounter{orcounter}
    }

    % -- Usage Example
    \begin{document}

    \begin{orlist}
      \oritem{example 1}
      \oritem{example 2}
    \end{orlist}

    \end{document}

答案3

我自己找到了解決方案:

\documentclass[a4paper]{article}

\newenvironment{ouenv}
{\left\lvert\begin{array}{l}}
{\end{array}\right.}

\begin{document}
\[\begin{ouenv}G\text{ abélien} \\ \text{ou} \\ I=\ensvide\end{ouenv}\]
\end{document}

它給出以下結果:

結果

(文字是法語,但這並不重要)

答案4

在同學的幫助下,我提出了一個新的解決方案,它看起來更像我原本想要的。它使用命令而不是環境,但它更好!

這是代碼:

\newcounter{orcounter}

\newenvironment{orlist}
{
\begin{array}{|l}
\setcounter{orcounter}{0}
}
{
\end{array}
}

\newcommand{\oritem}[1]{%
\ifthenelse{\theorcounter<1}{}{\\ \text{ou} \\}#1\stepcounter{orcounter}
}

\NewDocumentCommand{\orenv}{>{\SplitList{\\}}m}{%
\begin{orlist}\ProcessList{#1}{\oritem}\end{orlist}}

人們可以非常簡單地使用它,如下所示:

\[\orenv{G\text{ abélien} \\ I=\ensvide}\]

相關內容