# Fbox increase the spacing between the box and it content (inner margin)

Is there a way to control the top and bottom spacing between the box and it content (text)? and secondary about left and right spacing? in other words i am looking for the analogous of \arraystretch command in this case.

PS: here \parbox is used to allow line breaking.

\documentclass{article}
\begin{document}
\fbox{\parbox{\linewidth}{Hello world test example break this line\\
here is a new line just for the example}}
\end{document}

• No, not really -- \fboxsep is the spacing but it is used for all margins
– user31729
Jul 11, 2016 at 16:36
• They're all equal to \fboxsep . The default is 3pt, if I remember well. Jul 11, 2016 at 16:37
• If you want also the frame to break across pages, you can use the framed environment. Jul 11, 2016 at 16:39
• So if I change the value/length of fboxsep all fbox will be affected, unless i do it locally with groups {} is that possible?
– Cfun
Jul 11, 2016 at 16:40

By default, \fbox and the underlying \fr@meb@x use a single length \fboxsep for the separation of the box content from the box margin (and rule) -- This is easier of course and is also connected to the fact that in earlier times there weren't much length registers at hand just to squander them.

I've stolen the code from latex.ltx and changed the settings, using \fboxhsep and \fboxvsep, at the right places, to provide a solution without any extra package.

Of course, this \fboxother won't break over pages. For such things tcolorbox etc. is much easier.

\documentclass{article}

\makeatletter

\newlength{\fboxhsep}
\newlength{\fboxvsep}

\setlength{\fboxhsep}{5\fboxsep}
\setlength{\fboxvsep}{20\fboxsep}

\def\@frameb@xother#1{%
\@tempdima\fboxrule
\hbox{%
\lower\@tempdima\hbox{%
\vbox{%
\hrule\@height\fboxrule
\hbox{%
\vrule\@width\fboxrule
#1%
\vbox{%
\vskip\fboxvsep
\box\@tempboxa
\vskip\fboxvsep}%
#1%
\vrule\@width\fboxrule}%
\hrule\@height\fboxrule}%
}%
}%
}

\long\def\fboxother#1{%
\leavevmode
\setbox\@tempboxa\hbox{%
\color@begingroup
\kern\fboxhsep{#1}\kern\fboxhsep
\color@endgroup}%
\@frameb@xother\relax}

\makeatother
\begin{document}
\fboxother{\parbox{\linewidth}{Hello world test example break this line\\
here is a new line just for the example}}
\end{document}


Update

\documentclass{article}

\makeatletter

\newlength{\fboxhsep}
\newlength{\fboxvsep}

\newlength{\fboxtoprule}
\newlength{\fboxbottomrule}
\newlength{\fboxleftrule}
\newlength{\fboxrightrule}

\setlength{\fboxhsep}{5\fboxsep}
\setlength{\fboxvsep}{20\fboxsep}

\setlength{\fboxtoprule}{\fboxrule}
\setlength{\fboxleftrule}{\fboxrule}
\setlength{\fboxrightrule}{\fboxrule}
\setlength{\fboxbottomrule}{\fboxrule}

\def\@frameb@xother#1{%
\@tempdima\fboxtoprule
\hbox{%
\lower\@tempdima\hbox{%
\vbox{%
\hrule\@height\fboxtoprule
\hbox{%
\vrule\@width\fboxleftrule
#1%
\vbox{%
\vskip\fboxvsep
\box\@tempboxa
\vskip\fboxvsep}%
#1%
\vrule\@width\fboxrightrule}%
\hrule\@height\fboxbottomrule}%
}%
}%
}

\long\def\fboxother#1{%
\leavevmode
\setbox\@tempboxa\hbox{%
\color@begingroup
\kern\fboxhsep{#1}\kern\fboxhsep
\color@endgroup}%
\@frameb@xother\relax}

\newcommand{\myfbox}[3]{%
\begingroup
\setlength{\fboxhsep}{#1}
\setlength{\fboxvsep}{#2}
\fboxother{#3}

\endgroup
}

\makeatother
\begin{document}
\fboxother{\parbox{\linewidth}{Hello world test example break this line\\
here is a new line just for the example}}
\myfbox{1cm}{1.5cm}{\parbox{\linewidth}{Hello world test example break this line \\
here is a new line just for the example}}
\end{document}


• Most important is vertical space (top and bottom spacing) in my opinion, I am thinking about a command or macro the same as the command in my MWE which takes two arguments: vertical spacing and width length of course. \myfbox{width}{spacing}{text}
– Cfun
Jul 11, 2016 at 16:46
• @SAM: See the update please
– user31729
Jul 11, 2016 at 16:52
• Of course, the usage with the \parbox{\linewidth}` produces an overfull hbox
– user31729
Jul 11, 2016 at 16:56