命令完成前失敗

命令完成前失敗

我希望我的新命令即使使用多段落或 tikz 圖片作為參數也能正常運作。

\documentclass{article}
\usepackage{paralist,xparse,calc}

\NewDocumentCommand{\HorsListe}{sO{1}m}{%
    \IfBooleanTF{#1}{%
    \par\nopagebreak[4]\addvspace{1\itemsep}%
        \hspace{-#2\leftmargin}}{%
    \par\nopagebreak[4]\addvspace{2\itemsep}%
        \hspace{-#2\leftmargin}}%
    \begin{minipage}[t]{\linewidth+#2\leftmargin}
    #3

    \addvspace{3\itemsep}
    \end{minipage}%
    \nopagebreak[2]}


\begin{document}
\begin{itemize}
\item This works

\HorsListe{Something wide}

\item This doesn't work.

\HorsListe{Something wide

    with paragraph}

\item This doesn't work too

\HorsListe{\begin{tikzpicture}

\draw (0,0) rectangle (\linewidth,0) ;

\end{tikzpicture}}

\end{itemize}
\end{document}

答案1

的參數\NewDocumentCommand被假定為很短。你需要+讓它們變長:

\NewDocumentCommand{\HorsListe}{sO{1}+m}{ CODE HERE }

相關內容