\fbox around type area

The idea is to typeset a minipage and frame it; however we have to push it a bit leftwards and avoid overfull boxes; here's a way:

\documentclass{article}
\usepackage{lipsum}
\usepackage{xparse}

\newsavebox{\fminipagebox}
\NewDocumentEnvironment{fminipage}{m O{\fboxsep}}
 {\par\kern#2\noindent\begin{lrbox}{\fminipagebox}
  \begin{minipage}{#1}\ignorespaces}
 {\end{minipage}\end{lrbox}%
  \makebox[#1]{%
    \kern\dimexpr-\fboxsep-\fboxrule\relax
    \fbox{\usebox{\fminipagebox}}%
    \kern\dimexpr-\fboxsep-\fboxrule\relax
  }\par\kern#2
 }

\begin{document}

\lipsum[2]
\begin{fminipage}{\textwidth}
\lipsum[2]
\end{fminipage}
\lipsum[2]

\end{document}

You can also call it like

\begin{fminipage}{\textwidth}[1ex]

with any dimension you like, for stating the separation from the lines above and below (default is \fboxsep).

enter image description here


You can use a negative space to reset the indentation

\documentclass[a4paper]{scrartcl}
\usepackage{calc}

\begin{document}
\setlength{\parindent}{0cm}
text text text

\hspace{\dimexpr-\fboxrule-\fboxsep\relax}\fbox{%
  \begin{minipage}[t]{\widthof{text in box}}
    text in box
  \end{minipage}%
}

more text
\end{document}

Also you need to remove the spurious space with % after \fbox.

enter image description here


If i understand you correctly then you want to \hskip/\hspace* left by 2\fboxsep and \fboxrule.

\documentclass[a4paper]{scrartcl}
\usepackage{calc}

\begin{document}
\setlength{\parindent}{0cm}
text text text

\hspace*{\dimexpr-2\fboxsep-\fboxrule} \fbox{
  \begin{minipage}[t]{\textwidth - 2\fboxsep}
   text in box
  \end{minipage}
  }

  more text
  \end{document}

Tags:

Minipage