1

Consider the following code:

\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}

which produces the output:

enter image description here

QUESTION: How, using the UsestackEOL package, may I put opening and closing braces about the second displayed stack of sentences while maintaining the given structure of the stack? Removing the Centerstack command and leaving the open brace does not work. Also, is it possible to do this for brackets [] as well?

Thank you.

2 Answers 2

1

The \Centerstack provides an alignment option, so we choose here [l] for left alignment. Then, I merely need to indent those lines I want indented. They will not do it automatically, because the stack is not a paragraph, but merely a stack of individual lines.

p.s. The package is stackengine. the [usestackEOL] option to the package facilitates \\ tokens as the row separators, rather than the default space separator. One could alternately, without choosing that option, issue the directive \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}

enter image description here

To get brackets rather than braces, Replace \{ with [ and \} with ]. Note one has backslashes, the other not.

3
  • Thank you for this answer, Is it possible to display brackets instead of braces also?
    – DDS
    Apr 18, 2021 at 1:56
  • 1
    @mlchristians Replace \{ with [ and \} with ]. Note one has backslashes, the other not. Apr 18, 2021 at 1:57
  • Thank you again. The system has me waiting before it will let me accept the answer.
    – DDS
    Apr 18, 2021 at 1:59
1

With 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}

The optional argument can be B (default) for braces, b for brackets and p for parentheses. You can add other delimiters by adding more lines in the same fashion.

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .