lshort 的一个示例问题

lshort 的一个示例问题

\settowidth下面是书中如何使用获取动态宽度的示例

\flushleft
\newenvironment{vardesc}[1]{%
\settowidth{\parindent}{#1:\ }
\makebox[0pt][r]{#1:\ }}{}
\begin{displaymath}
a^2+b^2=c^2
\end{displaymath}
\begin{vardesc}{Where}$a$,
$b$ -- are adjacent to the right
angle of a right-angled triangle.
$c$ -- is the hypotenuse of
the triangle and feels lonely.
$d$ -- finally does not show up
here at all. Isn’t that puzzling?
\end{vardesc}

在此处输入图片描述

C这是一个非常有趣的例子。但是当我用语言风格输入它时

\newenvironment{vardesc}[1]{%
    \settowidth{\parindent}{#1:\ }
    \makebox[0pt][r]{#1:\ }
}{}

输出不同。 在此处输入图片描述

当我使用定义的环境时也发生了同样的事情vardesc

\begin{vardesc}{Where}
$a$,$b$ -- are adjacent to the right angle of a right-angled triangle.

$c$ -- is the hypotenuse of the triangle and feels lonely.

$d$ -- finally does not show up here at all. Isn't that puzzling?
\end{vardesc}

在此处输入图片描述

作者$a$故意写得一气呵成{Where}。我不知道为什么会这样。我的意思是我必须自己写代码,而不是从书上抄下来。那么,有什么好习惯可以把这样的事情做好呢?

答案1

我不太清楚您是否希望在页边空白处添加“Where”一词。因此,这里有两个基于的简单解决方案enumitem

\documentclass{article}
\usepackage[showframe]{geometry} 
\usepackage{enumitem}

\newenvironment{vardesc}[1]{%
\enumerate[wide=0pt, widest={#1:}, leftmargin=*]
\item[#1:]}
{\endenumerate}%

\newenvironment{varDesc}[1]{%
\itemize[leftmargin=0pt ]
\item[#1:]}%
{\enditemize}%
    \begin{document}

\flushleft
\begin{displaymath}
a^2+b^2=c^2
\end{displaymath}
\begin{vardesc}{Where}
$a$,$b$ -- are adjacent to the right angle of a right-angled triangle.

$c$ -- is the hypotenuse of the triangle and feels lonely.

$d$ -- finally does not show up here at all. Isn't that puzzling?
\end{vardesc}%

\begin{varDesc}{Where}
$a$,$b$ -- are adjacent to the right angle of a right-angled triangle.

$c$ -- is the hypotenuse of the triangle and feels lonely.

$d$ -- finally does not show up here at all. Isn't that puzzling?
\end{varDesc}%at all. Isn't that puzzling?

\end{document} 

在此处输入图片描述

相关内容