3

I would like to horizontally center the text in the \fbox:

\fbox{\vbox{\hbox{Words,}\hbox{words,}\hbox{and only words again}}}

How would I do this?

1
1

Tailor made for a stack. I show a normal stack on the left, an understack in the center and a centerstack on the right. Also, the left stack uses a space (default) as the end-of-line delimiter, while on the right 2 stacks, I have reset the end-of-line (EOL) delimiter to \cr.

\documentclass{article}
\usepackage{stackengine}
\begin{document}
\fbox{\Longstack{Words, words, {and only words again}}}
or 
\setstackEOL{\cr}%
\fbox{\Longunderstack{Words,\cr words,\cr and only words again}}
or 
\fbox{\Centerstack{Words,\cr words,\cr and only words again}}
\end{document}

enter image description here

Interline baseline skip can be reset with \setstackgap{L}{<length>}. Note also that center stacks add a \strut to each line, so that vertical centering is not affected by the presence of descenders. The strutting can be made the default for the other stacks as well, with the invocation of \strutlongstacks{T}.

2

Use a tabular.

\documentclass{article}

\begin{document}
  \fbox{%
    \begin{tabular}{@{}c@{}}
     words, \\
     words,\\
     and only words again
    \end{tabular}%
    }

    \begin{tabular}{|@{\hspace{\dimexpr\fboxsep+0.5\arrayrulewidth}}c@{\hspace{\dimexpr\fboxsep+0.5\arrayrulewidth}}|}\hline
     words, \\
     words,\\
     and only words again \\\hline
    \end{tabular}%

\end{document}

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.