1

Here is my MWE:

\documentclass[]{article}
\usepackage{showframe}
\usepackage{lipsum}
\usepackage{parskip}

\begin{document} \lipsum[1]

\fbox{ \begin{minipage}{\textwidth} \lipsum[1] \end{minipage} }

\end{document}

Why is there still a small indent and why is the minipage frame wider than the overall frame?

Werner
  • 603,163
Fin
  • 119

2 Answers2

3

You have some spurious spaces in your \fbox which causes the opening and closing spacing issues (see What is the use of percent signs (%) at the end of lines? (Why is my macro creating extra space?)). Also, the width of the text block should be reduced by the width of the \fbox's rule (\fboxrule) and the box gap (\fboxsep) twice (once for each side).

enter image description here

\documentclass{article}

\usepackage{showframe} \usepackage{lipsum} \usepackage{parskip}

\begin{document}

\lipsum[1]

% Note the use of '%' here... \fbox{% \begin{minipage}{\dimexpr\linewidth-2\fboxsep-2\fboxrule} \lipsum[1] \end{minipage}% }

\end{document}

Werner
  • 603,163
  • I used \linewidth although in this particular instance you can use \textwidth as well. \linewidth would be appropriate in general as it may change based on whether or not the margins change (as it does inside a list). – Werner Sep 08 '21 at 15:51
2

You want to take into account the \fboxsep and \fboxrule parameters. Here's a new environment fminipage that shares all syntax with minipage and does the computation by itself.

\documentclass[]{article}
\usepackage{parskip}

\usepackage{lipsum}

\ExplSyntaxOn % a handy function \cs_set_eq:NN \dimeval \dim_eval:n \ExplSyntaxOff

\newsavebox{\fminipagebox} \NewDocumentEnvironment{fminipage}{O{c}oO{#1}m} {% \begin{lrbox}{\fminipagebox} \IfNoValueTF{#2} {\begin{minipage}[#1]{\dimeval{#4-2\fboxsep-2\fboxrule}}} {\begin{minipage}[#1][#2][#3]{\dimeval{#4-2\fboxsep-2\fboxrule}}} } {% \end{minipage} \end{lrbox}\fbox{\usebox{\fminipagebox}}% }

\begin{document} \lipsum[1][1-4]

\begin{fminipage}{\textwidth} \lipsum[1][5-7] \end{fminipage}

\begin{center} x\begin{fminipage}[t][4cm][s]{4cm} \lipsum[2][1]

\vfill

\lipsum[2][2] \end{fminipage} \end{center}

\end{document}

enter image description here

egreg
  • 1,121,712