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.

In my case, I do not use any command about it. So the text is very close with the box and it is not good.

\documentclass{article}
\usepackage{amsmath,bm}


\begin{document}

P_above
\fbox{
 a=b
}
P_below
\end{document}
share|improve this question
1  
Are the above and below "paragraphs" math expressions or text? And are the above and below material really multi-line entities (paragraphs), or single-line entities? –  Steven B. Segletes Feb 25 at 14:31
1  
\[\boxed{a=b}\] is probably what you want. –  egreg Feb 25 at 14:33
    
And is the \fbox centered like a separate equation, or left-justified? And if centered, is it numbered like an equation? –  Steven B. Segletes Feb 25 at 14:38
    
I would recommend egreg's solution. –  Christian Hupfer Feb 25 at 15:16

4 Answers 4

up vote 4 down vote accepted

The context is not clear to me, thus there might be better solutions.

The following example defines \vsepfbox that adds additional vertical space around the \fbox with size \fboxsep. \sepfbox puts the space all around the \fbox:

\documentclass{article}
\usepackage{amsmath,bm}

\newcommand*{\sepfbox}[1]{%
  \begingroup
    \sbox0{\fbox{#1}}%
    \setlength{\fboxrule}{0pt}%
    \fbox{\unhbox0}%
  \endgroup
}
\newcommand*{\vsepfbox}[1]{%
  \begingroup
    \sbox0{\fbox{#1}}%
    \setlength{\fboxrule}{0pt}%
    \mbox{\kern-\fboxsep\fbox{\unhbox0}\kern-\fboxsep}%
  \endgroup
}

\begin{document}
  \noindent
  \qquad $P_\text{above}$\\
  $P_\text{left}$\fbox{$a=b$}$P_\text{right}$\\
  \null\qquad $P^\text{below}$

  \noindent
  \qquad $P_\text{above}$\\
  $P_\text{left}$\vsepfbox{$a=b$}$P_\text{right}$\\
  \null\qquad $P^\text{below}$

  \noindent
  \qquad $P_\text{above}$\\
  $P_\text{left}$\sepfbox{$a=b$}$P_\text{right}$\\
  \null\qquad $P^\text{below}$
\end{document}

Result

share|improve this answer
    
why the \null? –  A.Ellett Feb 26 at 1:20
    
@A.Ellett: At the begin of a line TeX removes white space like \qquad. \null is an empty box that prevents this. –  Heiko Oberdiek Feb 26 at 1:32

You have several options, but it's unclear what you really want.

If the boxed material is a math formula that should be centered, with amsmath you have \boxed. If the material is textual and you want it flush with the left margin, just place it inside a flushleft environment.

\documentclass{article}
\usepackage{amsmath}
\usepackage[nopar]{lipsum} % just for the example

\begin{document}
\lipsum[2]
\[
\boxed{a=b}
\]
\lipsum[3]
\begin{flushleft}
\fbox{some words}
\end{flushleft}
\lipsum[4]

\end{document}

enter image description here

share|improve this answer

I have another answer based on the suggestions given. I think, this is the requirement.

   \documentclass{article}
\usepackage{amsmath}
\usepackage{lipsum}
\begin{document}
\lipsum[1]
\begin{center}
\fbox{\quad $a=b$\quad}
\end{center}
\lipsum[2]
\end{document}

enter image description here

share|improve this answer

This should do it :)

  \documentclass{article}
  \usepackage{amsmath}
  \begin{document}

  $P_\text{above}$
  \fbox{
   a=b
  }
  $P_\text{below}$
  \end{document}

enter image description here

share|improve this answer
2  
I guess the OP wants vertical space, i.e. the box in an own line ;-) btw. one should prefer using $P_\text{below}$ to get the right font and spacing in the subscript text (needs amsmath.sty). –  Tobi Feb 25 at 14:51
    
@subhamsoni: I agree with Tobi, that the OP probably meant vertical space above and below the boxed content, 'P_above' etc. are just place holders for paragraphs above etc. –  Christian Hupfer Feb 25 at 15:11

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.