1

I am trying to add a frame around a text which would be centered and vertically aligned to the middle of the box but I can only center the text.

What should I do to align the text to the middle of the box?

\documentclass[12pt,a4paper,oneside]{letter}
\usepackage[left=2cm,right=2cm,top=2cm,bottom=2cm]{geometry}

\begin{document}

\noindent\fbox{\parbox{\linewidth\fboxrule\fboxsep}{\center\textbf{my text here}}}

\end{document}
2
  • I am not sure I understand the question \fbox{{\parbox{.5\linewidth}{\centering\rule{1cm}{2cm}}}} looks vertically aligned to me. Did you take into account the y descender of the my text here in asserting the vertical centering?
    – user4686
    Commented Dec 2, 2012 at 22:40
  • It depends on what you type, I had something else written in it and it was not vertically centered. There was more space at the top of it.
    – esmitex
    Commented Dec 3, 2012 at 0:22

1 Answer 1

3

Does this do what you want?

\documentclass[12pt,a4paper,oneside]{letter}
\usepackage{calc}
\usepackage[left=2cm,right=2cm,top=2cm,bottom=2cm]{geometry}

\begin{document}


\fbox{\begin{minipage}[t][4in][c]{\linewidth-2\fboxrule-2\fboxsep}
    \centering\textbf{my text here}
\end{minipage}}

\end{document}

enter image description here

3
  • Almost, I had to take off the "-2" because it would write "-2 -2" before my text.
    – esmitex
    Commented Dec 2, 2012 at 21:34
  • Did you use the calc package? That might be why -2 showed up.
    – A.Ellett
    Commented Dec 2, 2012 at 21:41
  • No, I didn't. I will try with it.
    – esmitex
    Commented Dec 3, 2012 at 0:20

You must log in to answer this question.

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