# \hfill doesn't work for braces in mathmode

I want a right brace that spans a few lines of text and is located at the right-most side of page.\

Something like this :

Here, the following code doesn't seem to work :

$\left.\begin{tabular}{l} line \\ one more line \end{tabular}\hfill\right\}$

Are there alternatives for \hfill that will work ?

• Please start by explaining what hvis piece of gode is suppose to do in the first place. Hfill doesnt make much sense here Nov 8, 2020 at 5:49

I'd abuse equation* for a couple of reasons:

1. automatic vertical spacing around the construction;
2. avoiding page breaks before the construction.

The contents of the braceonright environment is typeset as a tabular and reused for getting the right size of the brace. This is neessary, because \hfill does nothing if inside a \left-\right pair.

\documentclass{article}
\usepackage{amsmath}

\usepackage{lipsum} % for mock text

\newsavebox{\braceonrightbox}
\newenvironment{braceonright}
{%
\begin{equation*}% abuse equation* for spacing and other features
\hspace{0pt}% necessary
\begin{lrbox}{\braceonrightbox}% save the contents
\begin{tabular}{@{}l@{}}%
}
{%
\end{tabular}%
\end{lrbox}%
\usebox{\braceonrightbox}
\hspace{1000pt minus 1fil}
\left.\vphantom{\usebox{\braceonrightbox}}\right\rbrace
\end{equation*}\ignorespacesafterend
}

\begin{document}

\lipsum[1][1-6]
\begin{braceonright}
line \\
one more line
\end{braceonright}
\lipsum[2]

\end{document}

The trick is to add a very large space (1000pt) that can be shrinked to the actual width; in order for this to work, there must be some glue (0pt) at the beginning of the “equation”.

• Thanks ! This works exactly how I wanted it to be. Nov 8, 2020 at 14:18

Hm, something like this:

\documentclass{article}
\usepackage{lipsum}

\begin{document}
\lipsum[11]
\par\noindent
$\left.\begin{tabular}{@{} p{\linewidth} @{}} line \\ one more line \end{tabular}\right\}$
\par
\lipsum[11]
\end{document}