Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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}
share|improve this question
    
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? –  jfbu Dec 2 '12 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 Dec 3 '12 at 0:22
add comment

1 Answer 1

up vote 3 down vote accepted

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

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

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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