# Block of text that surrounded by vertically spanning parentheses

For my beamer slides, I like to have a command that centers a block of text and surrounds it by parentheses whose vertical size grows as the number of lines in the text grows.

I currently have the following:

\NewEnviron{remarkblock}[1][]{%
\scalebox{1}{%
$\scaleleftright{(}{\parbox{0.95\linewidth}{\centering \small\BODY}}{)}$
}
}


(don't ask me for explanations, I put this together from stackexchange bits)

This works almost fine. The only thing I'd like to improve is that when there is less than one line of text I would like the parentheses to not actually be 0.95 linewidths apart but just behave as normal parentheses (maybe a tad bigger) around centered text.

On https://en.wikibooks.org/wiki/LaTeX/Boxes I read that replacing \parbox by \pbox should do exactly what I want. However, I have two problems:

1. If the text contains a manual line break, I get an error: Somthings's broken -- Perhaps a missing \item

2. If I don't have a manual line break, it kind of works, but the pbox becomes left aligned even if I put \centering before \scaleleftright as well as before \pbox

EDIT: Upon request, here is a Minimal Working Example. In this version, I get the error; if I remove the \\ I get the left alignmnt, if I put a long text where the test is and remove the \\ everything is as desired.

\documentclass{article}
\usepackage{pbox}
\usepackage{scalerel}
\begin{document}
\scalebox{1}{$\centering\scaleleftright{(}{\centering\pbox{0.95\linewidth}{\centering \small test \\ test}}{)}$}
\end{document}


EDITED based on jbfu's comments, to fix outcome in lists.

\documentclass{article}
\usepackage[pass,showframe]{geometry}
\usepackage{pbox,scalerel,stackengine}
\usepackage[nopar]{lipsum}
\newcommand\myblock[1]{\noindent\hfill\belowbaseline[-\ht\strutbox]{{%
\scaleleftright[.025\linewidth]{(}{%
\pbox{\dimexpr0.95\linewidth}{\small\strut #1\strut}}{)}}}\hfill\mbox{}}
\begin{document}
\myblock{test}

\myblock{test\\test}

\myblock{test\\test\\test}

\myblock{\lipsum[1]}

\begin{enumerate}
\item \myblock{test\\test\\test}
\item \myblock{\lipsum[4]}
\item \lipsum[3]
\end{enumerate}
\end{document}


The varwidth package might be helpful:

\documentclass{article}
\usepackage{pbox}
\usepackage{scalerel}
\usepackage{varwidth}

\begin{document}
\centering

$\scaleleftright{(}{ \begin{varwidth}{0.95\linewidth} \small test \end{varwidth} }{)}$

$\scaleleftright{(}{ \begin{varwidth}{0.95\linewidth} \small test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test \end{varwidth} }{)}$
\end{document}


• I still get left alignment of the first bit with this – Bananach Jun 24 '18 at 11:21
• @Bananach Please see my edit. Is this the alignment you are looking for? If not, can you make a sketch to show the desired result? – samcarter_is_at_topanswers.xyz Jun 24 '18 at 11:25
• it is. however, optimally, I would like to have the centering included in the command block because I am creating an environment out of it – Bananach Jun 24 '18 at 11:25
• @Bananach You can include it in the definition of the \newenvironment without problem. – samcarter_is_at_topanswers.xyz Jun 24 '18 at 11:27