在嵌套对齐和枚举环境中到右边距的距离是多少?

在嵌套对齐和枚举环境中到右边距的距离是多少?

我正在使用设置\aligned中的环境\enumerate来格式化我的作业提交。我尝试使用\align*\flalign*\alignat环境,但它们在我的实验中表现不佳。我创建了一个新环境environ,将内容默认\item为数学模式(适合我的用例)。但是,当我需要输入较长的文本时,它会溢出右边距。

\textaligned在环境中溢出右边距:

文本溢出右边距的图像

为了解决这个问题,我创建了一个\mathbox命令,旨在创建一个\parbox从放置位置精确延伸到右边距的命令。不幸的是,计算似乎出错了,\parbox要么溢出,要么没有到达边距。

\parbox没有达到右边距:

\parbox 的图像未达到右边距

\parbox没有溢出右边距:

\parbox 溢出右边距的图像

这些是我的代码的相关部分:

\documentclass[10pt]{article}
% ...
\usepackage{geometry}
\geometry{a4paper}

%%% packages - not sure which ones were necessary so I just included them all
\usepackage{graphicx,booktabs,array,paralist,verbatim,subfig,sectsty, makecell,enumitem,titlesec,lmodern,slantsc,listings,setspace,amsmath, environ,showframe,nccmath,xifthen,adjustbox}
\usepackage[fleqn]{mathtools}
% ...
\subsectionfont{\fontsize{11}{13.75}\sffamily\mdseries\scshape}
\renewcommand{\labelenumi}{\textbf{Question \arabic*.}}
\renewcommand{\labelenumii}{(\arabic{enumi}.\arabic{enumii})}
\setlist[enumerate]{align=left, listparindent=2em, parsep=0pt}
% ...
\newenvironment{answergroup}{\begin{enumerate}[parsep=10pt]\begingroup\everymath{\displaystyle}
\setstretch {1.3}}{\endgroup\end{enumerate}}
\newenvironment{answerbody}{\begingroup\everymath{\displaystyle}
\setstretch {1.3}}{\endgroup}
\newcommand{\nextline}{\end{aligned}\\\begin{aligned}[t]&\\&}
\NewEnviron{aligneditem}[1][]{
    \begingroup
    %\allowdisplaybreaks - does nothing in aligned mode
    \setlength{\abovedisplayskip}{0pt}
    \setlength{\belowdisplayskip}{0pt}
    \setlength{\abovedisplayshortskip}{0pt}
    \setlength{\belowdisplayshortskip}{0pt}
    \ifthenelse{\isempty{#1}}
    {\item}
    {\item[#1]}
    $\begin{aligned}[t]
    &\BODY
    \end{aligned}$
    \endgroup
}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% THIS ↓ \dimexpr needs to be fixed somehow %%%%%%%%%%%%%%%
\newcommand{\mathbox}[1]{\boxed{\parbox[t]{\dimexpr\linewidth-\listparindent-\itemindent}{#1}}}%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{document}
\section{Basic Distributions}
\subsection{Binomial Distributions}
\begin{enumerate}
\setcounter{enumi}{3}
\begin{answerbody}
\begin{aligneditem}
\mathbox{
The binomial distribution arises when a random variable is determined to be the number of successes in a series of $n$ independent random trials. In these trials the probability of success is $p$ for each trial, and there are only two possible outcomes: success or failure.
}
\end{aligneditem}
\end{answerbody}
\begin{answerbody}
\begin{aligneditem}
\end{aligneditem}
\end{answerbody}
\begin{answergroup}
\begin{aligneditem}[\unskip]
\mu \geq \frac{5 * 0 + 30 * 1 + 56 * 2 + 15 * 3 + 10 * 4 + 7 * 5}{123} = \frac{262}{123} \\&
\implies \text{Possibly }X \sim \text{Po}(\lambda)\text{ where }\lambda \geq \frac{262}{123}\\&
\mathbox{It appears that sampled stroke patients make at least 2.13 errors on average on this psychometric test.}\\&
\displaystyle\sigma^{2} \geq \sum_{x}{\frac{(x-\mu)^{2}}{N}} \\&
= \frac{1}{123}\left(\begin{multlined}5\left(0 - \frac{262}{123}\right)^{2} + 30\left(1 - \frac{262}{123}\right)^{2} + 56\left(2 - \frac{262}{123}\right)^{2}\\
+ 15\left(3 - \frac{262}{123}\right)^{2} + 10\left(4 - \frac{262}{123}\right)^{2} + 10\left(5 - \frac{262}{123}\right)^{2}\end{multlined}\right)\\&
% ...
\end{aligneditem}
\end{answergroup}
\end{enumerate}
\end{document}

我应该如何正确计算右边距的剩余空间\parbox

答案1

\parbox我通过将的宽度改为 解决了这个问题\dimexpr\textwidth-\leftmargin-\listparindent+\parskip-\labelsep-\listparindent。我不太清楚为什么这样做有效,但对于我的用例来说,它会合理地接近边距而不会溢出。修改后的代码是:

\documentclass[10pt]{article}
% ...
\usepackage{geometry}
\geometry{a4paper}

%%% packages - not sure which ones were necessary so I just included them all
\usepackage{graphicx,booktabs,array,paralist,verbatim,subfig,sectsty, makecell,enumitem,titlesec,lmodern,slantsc,listings,setspace,amsmath, environ,showframe,nccmath,xifthen}
\usepackage[fleqn]{mathtools}
% ...
\subsectionfont{\fontsize{11}{13.75}\sffamily\mdseries\scshape}
\renewcommand{\labelenumi}{\textbf{Question \arabic*.}}
\renewcommand{\labelenumii}{(\arabic{enumi}.\arabic{enumii})}
\setlist[enumerate]{align=left, listparindent=2em, parsep=0pt}
% ...
\newenvironment{answergroup}{\begin{enumerate}[parsep=10pt]\begingroup\everymath{\displaystyle}
\setstretch {1.3}}{\endgroup\end{enumerate}}
\newenvironment{answerbody}{\begingroup\everymath{\displaystyle}
\setstretch {1.3}}{\endgroup}
\newcommand{\nextline}{\end{aligned}\\\begin{aligned}[t]&\\&}
\newcommand{\textbox}[1]{\boxed{\parbox[t]{\dimexpr\textwidth-\leftmargin-\listparindent+\parskip-\labelsep-\listparindent}{#1}}}
\NewEnviron{aligneditem}[1][]{
    \begingroup
    %\allowdisplaybreaks - does nothing in aligned mode
    \setlength{\abovedisplayskip}{0pt}
    \setlength{\belowdisplayskip}{0pt}
    \setlength{\abovedisplayshortskip}{0pt}
    \setlength{\belowdisplayshortskip}{0pt}
    \ifthenelse{\isempty{#1}}
    {\item}
    {\item[#1]}
    $\begin{aligned}[t]
    &\BODY
    \end{aligned}$
    \endgroup
}
\begin{document}
\section{Basic Distributions}
\subsection{Binomial Distributions}
\begin{enumerate}
\setcounter{enumi}{3}
\begin{answerbody}
\begin{aligneditem}
\textbox{
The binomial distribution arises when a random variable is determined to be the number of successes in a series of $n$ independent random trials. In these trials the probability of success is $p$ for each trial, and there are only two possible outcomes: success or failure.
}
\end{aligneditem}
\end{answerbody}
\begin{answerbody}
\begin{aligneditem}
\end{aligneditem}
\end{answerbody}
\begin{answergroup}
\begin{aligneditem}[\unskip]
\mu \geq \frac{5 * 0 + 30 * 1 + 56 * 2 + 15 * 3 + 10 * 4 + 7 * 5}{123} = \frac{262}{123} \\&
\implies \text{Possibly }X \sim \text{Po}(\lambda)\text{ where }\lambda \geq \frac{262}{123}\\&
\textbox{It appears that sampled stroke patients make at least 2.13 errors on average on this psychometric test.}\\&
\displaystyle\sigma^{2} \geq \sum_{x}{\frac{(x-\mu)^{2}}{N}} \\&
= \frac{1}{123}\left(\begin{multlined}5\left(0 - \frac{262}{123}\right)^{2} + 30\left(1 - \frac{262}{123}\right)^{2} + 56\left(2 - \frac{262}{123}\right)^{2}\\
+ 15\left(3 - \frac{262}{123}\right)^{2} + 10\left(4 - \frac{262}{123}\right)^{2} + 10\left(5 - \frac{262}{123}\right)^{2}\end{multlined}\right)\\&
% ...
\end{aligneditem}
\end{answergroup}
\end{enumerate}
\end{document}

它产生以下输出: 正确对齐的最终输出

相关内容