如何使用 UsestackEOL 包将大括号 [方括号] 放在结构化堆栈周围

如何使用 UsestackEOL 包将大括号 [方括号] 放在结构化堆栈周围

考虑以下代码:

\documentclass{article}
\usepackage[usestackEOL]{stackengine}

\begin{document}

\thispagestyle{empty}
\Large
$\left\{
\Centerstack{
the first sentence. \\
the second sentence is longer. \\
the third sentence is even longer than that. \\
the fourth sentence is the longest of all four sentences.}
\right\}$

\vskip 35pt

\noindent the first sentence. 
\par the second sentence is longer. \\
\noindent the third sentence is even longer than that. 
\par the fourth sentence is the longest of all four sentences.
\end{document}

输出结果如下:

在此处输入图片描述

问题:如何使用 UsestackEOL 包在第二个显示的句子堆栈周围放置左括号和右括号,同时保持堆栈的给定结构?删除 Centerstack 命令并保留左括号不起作用。此外,是否也可以对括号 [] 执行此操作?

谢谢。

答案1

提供\Centerstack了对齐选项,因此我们在这里选择[l]左对齐。然后,我只需要缩进我想要缩进的行。它们不会自动执行此操作,因为堆栈不是段落,而只是单个行的堆栈。

ps 软件包为stackengine[usestackEOL]软件包的选项允许使用\\标记作为行分隔符,而不是默认的空格分隔符。也可以不选择该选项,而是发出指令\setstackEOL{\\}

\documentclass{article}
\usepackage[usestackEOL]{stackengine}
\newcommand\myindent{\hspace{\parindent}}
\begin{document}

\thispagestyle{empty}
\Large
$\left\{
\Centerstack[l]{
the first sentence. \\
\myindent the second sentence is longer. \\
the third sentence is even longer than that. \\
\myindent the fourth sentence is the longest of all four sentences.}
\right\}$

\vskip 35pt

\noindent the first sentence. 
\par the second sentence is longer. \\
\noindent the third sentence is even longer than that. 
\par the fourth sentence is the longest of all four sentences.
\end{document}

在此处输入图片描述

要使用括号而不是大括号,请将 和 替换\{[\}注意]一个有反斜杠,另一个没有。

答案2

varwidth

\documentclass{article}
\usepackage{varwidth}

\newenvironment{mystack}[1][B]
 {% keep the parindent
  \edef\keptparindent{\the\parindent}%
  $\left
  \if#1B \{\def\mystackfence{\}}\fi
  \if#1b [\def\mystackfence{]}\fi
  \if#1p (\def\mystackfence{)}\fi\,
  \begin{varwidth}{\columnwidth}\setlength{\parindent}{\keptparindent}%
 }
 {\end{varwidth}\,\right\mystackfence$}

\begin{document}

\begin{mystack}
\centering
the first sentence. \\
the second sentence is longer. \\
the third sentence is even longer than that. \\
the fourth sentence is the longest of all four sentences.
\end{mystack}

\vspace{35pt}

\begin{mystack}[b]
\noindent the first sentence. 
\par the second sentence is longer. \\
\noindent the third sentence is even longer than that. 
\par the fourth sentence is the longest of all four sentences.
\end{mystack}

\end{document}

可选参数可以是B(默认)大括号、b方括号和p圆括号。您可以按照相同的方式添加更多行来添加其他分隔符。

在此处输入图片描述

相关内容