How to enlarge boxes vertically?

You can control the inner separation using \fboxsep. Unfortunately, that’s for vertical and horizontal distance, but apparently you also wanted more distance to left and right.

\documentclass{article}
\usepackage{amsmath}

\newcommand\boxedB[1]{{\setlength\fboxsep{10pt}\boxed{#1}}}

\begin{document}
\[
\boxedB{
  \left |\int_0^1 f(x)g(x)dx\right | \leq \sqrt{\int_0^1|f(x)|^2 dx}\cdot\sqrt{\int_0^1|g(x)|^2 dx}
}
\]
\end{document}

enter image description here


The definition of \boxed is not super-sophisticated, so we could also simpy extend it to take an optional argument which is the desired distance.

\documentclass{article}
\usepackage{amsmath}

\makeatletter
\renewcommand\boxed[2][\fboxsep]{% by default take current \fboxsep
  {%
    \setlength\fboxsep{#1}%
    \fbox{\m@th$\displaystyle#2$}% <-- original \boxed
  }%
}
\makeatother

\begin{document}
\[
\boxed[10pt]{
  \left |\int_0^1 f(x)g(x)dx\right | \leq \sqrt{\int_0^1|f(x)|^2 dx}\cdot\sqrt{\int_0^1|g(x)|^2 dx}
}
\]
\end{document}

You can set separately the padding at the sides and at top/bottom:

\documentclass{article}
\usepackage{amsmath}
\usepackage{xparse}

\ExplSyntaxOn
\NewDocumentCommand{\xboxed}{O{}m}
 {
  \group_begin:
  \keys_set:nn { colas/xboxed } { #1 }
  \dim_set_eq:NN \fboxsep \l_colas_xboxed_tb_dim
  \boxed
   {
    \dim_compare:nF { \l_colas_xboxed_lr_dim = 0pt }
     {
      \hspace{-\fboxsep}\hspace{\l_colas_xboxed_lr_dim}
     }
    #2
    \dim_compare:nF { \l_colas_xboxed_lr_dim = 0pt }
     {
      \hspace{-\fboxsep}\hspace{\l_colas_xboxed_lr_dim}
     }
   }
  \group_end:
 }
\NewDocumentCommand{\xboxedset}{m}
 {
  \keys_set:nn { colas/xboxed } { #1 }
 }
\keys_define:nn { colas/xboxed }
 {
  lr .dim_set:N = \l_colas_xboxed_lr_dim,
  tb .dim_set:N = \l_colas_xboxed_tb_dim,
 }
\ExplSyntaxOff

\begin{document}

\[
\xboxed[tb=9pt]{
  \left |\int_0^1 f(x)g(x)\,dx\right | \leq
  \sqrt{\int_0^1|f(x)|^2\,dx}\cdot\sqrt{\int_0^1|g(x)|^2\,dx}
}
\]
\[
\xboxed[lr=3pt,tb=9pt]{
  \left |\int_0^1 f(x)g(x)\,dx\right | \leq
  \sqrt{\int_0^1|f(x)|^2\,dx}\cdot\sqrt{\int_0^1|g(x)|^2\,dx}
}
\]
\xboxedset{tb=9pt}
\[
\xboxed{
  \left |\int_0^1 f(x)g(x)\,dx\right | \leq
  \sqrt{\int_0^1|f(x)|^2\,dx}\cdot\sqrt{\int_0^1|g(x)|^2\,dx}
}
\]
\[
\xboxed[lr=3pt]{
  \left |\int_0^1 f(x)g(x)\,dx\right | \leq
  \sqrt{\int_0^1|f(x)|^2\,dx}\cdot\sqrt{\int_0^1|g(x)|^2\,dx}
}
\]
\end{document}

If lr is not given a value, the same padding as top/bottom is used.

The setting is local for the particular \xboxed (and nested ones, of course, unless countermanded) or it can be set for the current group (or even document-wise in the preamble) with \xboxedset.

enter image description here


A non-framed version can be obtained by storing the content in a box, \mybox, and then adding a bar with extra height and depth in front of it. In this example \mybox is defined with \ensuremath{\displaystyle #2} since it is supposed to be used in displayed math. The same approach can be used together with \boxed to not add horizontal space, or in other other boxes without the math declarations.

\documentclass{article}
\usepackage{amsmath}
\usepackage{calc}
\newdimen\myextraHT
\myextraHT=5mm
\newsavebox\mybox%
\newcommand\HTbox[2][\myextraHT]{%
  \savebox\mybox{\ensuremath{\displaystyle #2}}%
  \raisebox{-\dp\mybox-#1}{\rule{0pt}{\ht\mybox+\dp\mybox+#1+#1}}%
  \usebox\mybox
}
\begin{document}
A row of text to show where the box horisontal start and end
\begin{displaymath}
  \left |\int_0^1 f(x)g(x)dx\right | \leq \sqrt{\int_0^1|f(x)|^2 dx}\cdot\sqrt{\int_0^1|g(x)|^2 dx} 
\end{displaymath}
A row of text to show where the box horisontal start and end
\begin{displaymath}
  \HTbox{\left |\int_0^1 f(x)g(x)dx\right | \leq \sqrt{\int_0^1|f(x)|^2 dx}\cdot\sqrt{\int_0^1|g(x)|^2 dx}}
\end{displaymath}
A row of text to show where the box horisontal start and end
\begin{displaymath}
  \HTbox[20mm]{\left |\int_0^1 f(x)g(x)dx\right | \leq \sqrt{\int_0^1|f(x)|^2 dx}\cdot\sqrt{\int_0^1|g(x)|^2 dx}}
\end{displaymath}
A row of text to show where the box horisontal start and end
\end{document}

enter image description here

To get a framed version, as requested in the question, an \fbox can be added to the command:

\newcommand\HTbox[2][\myextraHT]{%
  \savebox\mybox{\ensuremath{\displaystyle #2}}%
  \fbox{\raisebox{-\dp\mybox-#1}{\rule{0pt}{\ht\mybox+\dp\mybox+#1+#1}}%
    \usebox\mybox}
}

Then the framed equations becomes:

enter image description here

Tags:

Spacing

Boxes