2

This seems like such a simple problem but I cannot seem to find an answer mixed in all the questions about drawing boxes.

I want to be able to draw a bounding, not a frame, but a bounding box. One with zero extra size around any object: a minipage, a paragraph, a tikz picture, a figure, a table, whatever.

For the purposes of illustrating how large something is on the page I want to encapsulate it a box. This means that adding the bounding box to the page must not change any of the page layout.

I of course expect these boxes to be ugly, their only purpose is for drafting needs to measure distances, similar to the showframe option for \geometry.

If my understanding about TeX is correct, everything ever drawn on a page is a box. Is there a way to simply draw this box?

EDIT-----------------------------------------------------------------

I have added a minimum working example depicting the problems with the (at the time of 1:53pm) suggestions so far.

\documentclass[fontsize=12pt,twoside=false,]{scrbook}
\usepackage{babel}
\usepackage{listings}
\usepackage{geometry}
\usepackage{parskip}

\usepackage{lipsum} % Just for the MWE


\begin{document}
%Phelype Oleiniks Suggestion
\fboxsep=0pt \fboxrule=1sp

%This doesnt work
\fbox{\lipsum[1]}

%This doesnt work either
\fbox{Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Ut purus elit, vestibulum
ut, placerat ac, adipiscing vitae, felis. Curabitur dictum gravida mauris. Nam arcu
libero, nonummy eget, consectetuer id, vulputate a, magna. Donec vehicula augue
eu neque. Pellentesque habitant morbi tristique senectus et netus et malesuada
fames ac turpis egestas. Mauris ut leo. Cras viverra metus rhoncus sem. Nulla
et lectus vestibulum urna fringilla ultrices.  Phasellus eu tellus sit amet tortor
gravida placerat.  Integer sapien est, iaculis in, pretium quis, viverra ac, nunc.
Praesent eget sem vel leo ultrices bibendum. Aenean faucibus. Morbi dolor nulla,
malesuada eu, pulvinar at, mollis ac, nulla. Curabitur auctor semper nulla. Donec
varius orci eget risus. Duis nibh mi, congue eu, accumsan eleifend, sagittis quis,
diam. Duis eget orci sit amet orci dignissim rutru}

%Putting it inside a minipage works for unknown reasons.
\fbox{\begin{minipage}[t]{\linewidth}%
    \lipsum[1]%
\end{minipage}}

%demonstration of poor baseline with \frame{}
Oh how \fbox{Frustrating!}!

Oh how \frame{Frustrating!}!


%this even breaks the compiler
% \fbox{\begin{lstlisting}
%     Here is some code

%     More code = 4;
% \end{lstlisting}}

\end{document}
2

\frame{...} draws a frame around its content without additional space:

\documentclass{article}

\begin{document}
\sbox{0}{Hello!}\the\wd0, \the\ht0

\sbox{0}{\frame{Hello!}}\the\wd0, \the\ht0
\end{document}
  • If we surround each letter of a word, all the letters are framed but we lose their baseline: they are all aligned "all down". – AndréC Oct 3 '19 at 20:14
  • Thank you, I wasn't aware of this side effect. – AlexG Oct 3 '19 at 20:21
  • I cannot appear to get this to function like so \frame{\lipsum[1]}. The paragraph shoots off the side of the right side of the page. In fact I cannot make this work for even the most basic paragraph, with the same behavior of it causes the paragraph to shoot off the right side of the page. – Bob Oct 3 '19 at 20:41
  • A paragraph isn't a box. You may put it in a \parbox – AlexG Oct 3 '19 at 21:34
  • Doesnt a paragraph by default make a box? How does Tex know to make the next paragraph where it needs to be if there is no reference point for the last paragraph? – Bob Oct 3 '19 at 21:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.