访问新环境声明末尾的#1

访问新环境声明末尾的#1

我正在撰写一份回忆录文件,正在努力定义一个新环境,以便我能够将图表放在正文中,并将其标题放在外边距中。这是我序言的摘录,没有定义这样的环境。

\documentclass[10pt]{memoir}                        %document class
\setstocksize{240mm}{150mm}

\usepackage[T1]{fontenc}                            %font output
\usepackage[utf8]{inputenc}                         %font input
\usepackage[english]{babel} 

\usepackage{lipsum}
\usepackage{marginfix}
\usepackage{graphicx}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% PAGE LAYOUT
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\usepackage{geometry}

\let\footruleskip\undefined                         %headings
\usepackage{fancyhdr}
\nouppercaseheads

\settrimmedsize{240mm}{150mm}{*}
\setlength{\trimtop}{0pt}
\setlength{\trimedge}{\stockwidth}
\addtolength{\trimedge}{-\paperwidth}
\settypeblocksize{193mm}{84mm}{*}
\setulmargins{27mm}{*}{*}
\setlrmargins{18mm}{*}{*}
\setmarginnotes{3mm}{3.5cm}{\onelineskip}
\setheadfoot{\onelineskip}{\onelineskip}
\setlength{\headsep}{1.2cm}
%\setheaderspaces{*}{2\onelineskip}{*}
\checkandfixthelayout

\addtolength{\footskip}{0.55cm}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% CAPTION LAYOUT
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\usepackage{caption}                                %customized captions
\captionsetup{font=footnotesize, labelfont={bf}}
\usepackage{captdef}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% FULLWIDTH
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\usepackage[outermargin=-3.5cm]{fullwidth}

\newenvironment{fullwidthblocked}{%
\blockmargin%
\begin{fullwidth}%
}{%
\end{fullwidth}%
\unblockmargin%
}

我想我可以用来fullwidthblocked定义新的环境,所以我尝试了这个解决方案

\newenvironment{figureDX}[1]{%
\begin{fullwidthblocked}%
\begin{minipage}{84mm}%
\centering%
#1%
\end{minipage}%
\hspace{1.5mm}%
\begin{minipage}{3.5cm}%
}{%
\end{minipage}%
\end{fullwidthblocked}%
}

可用于正文写作

\begin{figureDX}{\includegraphics[scale=•]{•}}
\figcaption{•}\label{•}
\end{figureDX}

这确实有效,但只适用于奇数页,因为它将标题放在图片的右侧。然后我尝试调整这几行来介绍偶数页的对应内容:

\newenvironment{figureSX}[1]{%
\begin{fullwidthblocked}%
\begin{minipage}{3.5cm}%
}{%
\end{minipage}%
\hspace{1.5mm}%
\begin{minipage}{84mm}%
#1%
\end{minipage}%
\end{fullwidthblocked}%
}

但这会返回错误! Illegal parameter number in definition of \endfigureSX.,我不知道如何解决。

我知道我提出的解决方案既不优雅也不紧凑,但至少我希望它能够发挥作用。有什么想法可以解决这个问题吗?

答案1

在正常的 LaTeX2e 中,\newenvironment构造不允许访问#1环境的最终部分。

在这种情况下,LaTeX3xparse可以提供帮助。它提供了

\NewDocumentEnvironment{envname}{ arg specification }{ start }{ end }

加上#1可从末尾部分访问的加法。请注意,这arg specification与 使用的基于数字的加法非常不同\newenvironment

相关内容