使用 `multicols` 环境的新环境

使用 `multicols` 环境的新环境

在下面的代码中,我想定义环境的自定义版本multicols。输出很好,但编译发送以下消息:\begin{submulticols} on input line 95 ended by \end{multicols}。我做错了什么?

\documentclass[]{article}
    \usepackage{multicol}

    \newlength{\mycolumnsep}
    \newlength{\mycolumnseprule}

    \setlength{\mycolumnsep}{1cm}
    \setlength{\mycolumnseprule}{0.2pt}


    \newlength{\mysubcolumnsep}
    \newlength{\mysubcolumnseprule}

    \setlength{\mysubcolumnsep}{0.5cm}
    \setlength{\mysubcolumnseprule}{0pt}


    \setlength{\columnsep}{\mycolumnsep}
    \setlength{\columnseprule}{\mycolumnseprule}


    \newenvironment{submulticols}[1]{%
        \setlength{\columnsep}{\mysubcolumnsep}
        \setlength{\columnseprule}{\mysubcolumnseprule}
        \begingroup
        \multicols{#1}
    }{%
        \endmulticols
        \endgroup
        %\setlength{\columnsep}{\mycolumnsep}
        %\setlength{\columnseprule}{\mycolumnseprule}
    }


\begin{document}

\section{Exemple 1}

\begin{multicols}{2}
    bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla
    bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla
    bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla
    bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla
    bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla
    bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla
    bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla
    bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla

    \begin{submulticols}{2}
        ok ok ok ok ok ok ok ok ok ok ok ok ok ok
        ok ok ok ok ok ok ok ok ok ok ok ok ok ok
        ok ok ok ok ok ok ok ok ok ok ok ok ok ok
        ok ok ok ok ok ok ok ok ok ok ok ok ok ok
        ok ok ok ok ok ok ok ok ok ok ok ok ok ok
        ok ok ok ok ok ok ok ok ok ok ok ok ok ok
        ok ok ok ok ok ok ok ok ok ok ok ok ok ok
        ok ok ok ok ok ok ok ok ok ok ok ok ok ok
        ok ok ok ok ok ok ok ok ok ok ok ok ok ok
        ok ok ok ok ok ok ok ok ok ok ok ok ok ok
        ok ok ok ok ok ok ok ok ok ok ok ok ok ok
    \end{submulticols}


    bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla
    bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla
    bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla
    bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla
    bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla
    bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla
    bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla
    bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla
\end{multicols}


\section{Exemple 2}

\begin{multicols}{2}
    bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla
    bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla
    bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla
    bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla
    bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla
    bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla
    bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla
    bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla

    bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla
    bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla
    bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla
    bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla
    bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla
    bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla
    bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla
    bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla


    \begin{submulticols}{4}
        ok ok ok ok ok ok ok ok ok ok ok ok ok ok
        ok ok ok ok ok ok ok ok ok ok ok ok ok ok
        ok ok ok ok ok ok ok ok ok ok ok ok ok ok
        ok ok ok ok ok ok ok ok ok ok ok ok ok ok
        ok ok ok ok ok ok ok ok ok ok ok ok ok ok
        ok ok ok ok ok ok ok ok ok ok ok ok ok ok
        ok ok ok ok ok ok ok ok ok ok ok ok ok ok
        ok ok ok ok ok ok ok ok ok ok ok ok ok ok
        ok ok ok ok ok ok ok ok ok ok ok ok ok ok
        ok ok ok ok ok ok ok ok ok ok ok ok ok ok
        ok ok ok ok ok ok ok ok ok ok ok ok ok ok 
    \end{submulticols}
\end{multicols}

\end{document}

答案1

使用\begin{multicols}\end{multicols},因为环境依赖于看到\end

您不需要\begingroupand \endgroup,因为环境已经形成了一个组。

\documentclass[]{article}
\usepackage{multicol}

\newlength{\mycolumnsep}
\newlength{\mycolumnseprule}
\setlength{\mycolumnsep}{1cm}
\setlength{\mycolumnseprule}{0.2pt}

\newlength{\mysubcolumnsep}
\newlength{\mysubcolumnseprule}
\setlength{\mysubcolumnsep}{0.5cm}
\setlength{\mysubcolumnseprule}{0pt}

\setlength{\columnsep}{\mycolumnsep}
\setlength{\columnseprule}{\mycolumnseprule}


\newenvironment{submulticols}[1]{%
  \setlength{\columnsep}{\mysubcolumnsep}%
  \setlength{\columnseprule}{\mysubcolumnseprule}%
  \begin{multicols}{#1}
}{%
  \end{multicols}
}


\begin{document}

\section{Exemple 1}

\begin{multicols}{2}
bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla
bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla
bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla
bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla
bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla
bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla
bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla
bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla

\begin{submulticols}{2}
ok ok ok ok ok ok ok ok ok ok ok ok ok ok
ok ok ok ok ok ok ok ok ok ok ok ok ok ok
ok ok ok ok ok ok ok ok ok ok ok ok ok ok
ok ok ok ok ok ok ok ok ok ok ok ok ok ok
ok ok ok ok ok ok ok ok ok ok ok ok ok ok
ok ok ok ok ok ok ok ok ok ok ok ok ok ok
ok ok ok ok ok ok ok ok ok ok ok ok ok ok
ok ok ok ok ok ok ok ok ok ok ok ok ok ok
ok ok ok ok ok ok ok ok ok ok ok ok ok ok
ok ok ok ok ok ok ok ok ok ok ok ok ok ok
ok ok ok ok ok ok ok ok ok ok ok ok ok ok
\end{submulticols}


bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla
bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla
bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla
bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla
bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla
bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla
bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla
bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla
\end{multicols}


\section{Exemple 2}

\begin{multicols}{2}
bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla
bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla
bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla
bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla
bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla
bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla
bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla
bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla

bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla
bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla
bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla
bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla
bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla
bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla
bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla
bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla


\begin{submulticols}{4}
ok ok ok ok ok ok ok ok ok ok ok ok ok ok
ok ok ok ok ok ok ok ok ok ok ok ok ok ok
ok ok ok ok ok ok ok ok ok ok ok ok ok ok
ok ok ok ok ok ok ok ok ok ok ok ok ok ok
ok ok ok ok ok ok ok ok ok ok ok ok ok ok
ok ok ok ok ok ok ok ok ok ok ok ok ok ok
ok ok ok ok ok ok ok ok ok ok ok ok ok ok
ok ok ok ok ok ok ok ok ok ok ok ok ok ok
ok ok ok ok ok ok ok ok ok ok ok ok ok ok
ok ok ok ok ok ok ok ok ok ok ok ok ok ok
ok ok ok ok ok ok ok ok ok ok ok ok ok ok 
\end{submulticols}
\end{multicols}

\end{document}

在此处输入图片描述

相关内容