如何在输入枚举之前知道两列文档中枚举的行宽?

如何在输入枚举之前知道两列文档中枚举的行宽?

在此处输入图片描述

我想填充以下长度在进入普查前(或者可能在进入document环境之前)让我不用担心初始化是否已经被调用。

\newlength\EWD
\newlength\HWD
\newlength\HHWD

初始化程序如下,

\def\Init{%
    \settowidth{\EWD}{${}={}$}%
    \setlength{\HWD}{0.5\dimexpr\linewidth-\EWD\relax}%
    \setlength{\HHWD}{0.5\HWD}}

以下是我的真实情况。

在此处输入图片描述

\documentclass[twocolumn]{article}
\usepackage[a4paper,margin=1cm]{geometry}
\usepackage{mathtools}
\newlength\EWD
\newlength\HWD
\newlength\HHWD

\def\Init{%
    \settowidth{\EWD}{${}={}$}%
    \setlength{\HWD}{0.5\dimexpr\linewidth-\EWD\relax}%
    \setlength{\HHWD}{0.5\HWD}}

\def\TopLHS#1{\mathrlap{#1}\rule{\HWD}{0pt}}
\def\MiddleLHS#1{\rule{\HHWD}{0pt}\mathclap{#1}\rule{\HHWD}{0pt}}
\def\BottomLHS#1{\rule{\HWD}{0pt}\mathllap{#1}}

\begin{document}

\begin{enumerate}
\item\Init
$\!
\begin{aligned}[t]  
\TopLHS{\framebox[3cm]{Top LHS}}\\
\MiddleLHS{\framebox[3cm]{Middle LHS}}\\
\BottomLHS{\framebox[3cm]{Bottom LHS}}
    &= \begin{multlined}[t][\HWD]
            \framebox[3cm]{Top RHS 1}\\
            \framebox[3cm]{Middle RHS 1}\\
            \framebox[3cm]{Bottom RHS 1}
        \end{multlined}\\
    &= \begin{multlined}[t][\HWD]
            \framebox[3cm]{Top RHS 2}\\
            \framebox[3cm]{Middle RHS 2}\\
            \framebox[3cm]{Bottom RHS 2}
        \end{multlined}
\end{aligned}
$
\end{enumerate}
\end{document}

欢迎任何建议!

答案1

\Init这只是将添加作为首要任务的问题\item;其他地方不能保证参数得到正确评估

\documentclass[twocolumn]{article}
\usepackage[a4paper,margin=1cm]{geometry}
\usepackage{mathtools}

\AtBeginDocument{%
  \expandafter\def\expandafter\item\expandafter{%
    \expandafter\Init\item}%
}



\newlength\EWD
\newlength\HWD
\newlength\HHWD

\def\Init{%
    \settowidth{\EWD}{${}={}$}%
    \setlength{\HWD}{0.5\dimexpr\linewidth-\EWD\relax}%
    \setlength{\HHWD}{0.5\HWD}}

\def\TopLHS#1{\mathrlap{#1}\rule{\HWD}{0pt}}
\def\MiddleLHS#1{\rule{\HHWD}{0pt}\mathclap{#1}\rule{\HHWD}{0pt}}
\def\BottomLHS#1{\rule{\HWD}{0pt}\mathllap{#1}}

\def\showInit{\texttt{EWD=\the\EWD; HWD=\the\HWD; HHWD=\the\HHWD}}

\begin{document}

\begin{enumerate}
\item
$\!
\begin{aligned}[t]  
\TopLHS{\framebox[3cm]{Top LHS}}\\
\MiddleLHS{\framebox[3cm]{Middle LHS}}\\
\BottomLHS{\framebox[3cm]{Bottom LHS}}
    &= \begin{multlined}[t][\HWD]
            \framebox[3cm]{Top RHS 1}\\
            \framebox[3cm]{Middle RHS 1}\\
            \framebox[3cm]{Bottom RHS 1}
        \end{multlined}\\
    &= \begin{multlined}[t][\HWD]
            \framebox[3cm]{Top RHS 2}\\
            \framebox[3cm]{Middle RHS 2}\\
            \framebox[3cm]{Bottom RHS 2}
        \end{multlined}
\end{aligned}
$
\item\showInit
  \begin{itemize}
  \item\showInit
  \end{itemize}
\end{enumerate}
\end{document}

在此处输入图片描述

\showItem只是为了展示参数的值,其内部itemize应该是不同的。

相关内容