I have several frameboxes in my document, using the following command:

\framebox(115,115){ R-Sq: \newline For example} 

I want to force a new line, but neither \newline or \\ appear to work. Is there any other way of doing this?


TH. has suggested putting the framebox around another box, but specifying the size can be awkward. Here's my (note: plug) solution to the problem:

\minibox[frame]{R-Sq:\\ For example}

A ‘minibox’ is exactly equivalent to a tabular in the current implementation; I just wanted the shorter markup.

  • Thank you - that also worked. As I have several frameboxes, I am using both answers to be equitable! – celenius Jan 11 '11 at 2:13
  • 2
    @celenius I forgot to mention you can also centre the contents by writing \minibox[c] if that helps. – Will Robertson Jan 11 '11 at 2:18
  • Yeah, the length is sort of awkward. As I recall from when I looked a few hours ago, it basically did \vbox to #1\unitlength{\vss\hbox to #2\unitlength{\hss#4\hss}\vss}, so that's where I got the width of the \parbox. – TH. Jan 11 '11 at 6:36
  • \minibox even has a frame argument, nice. – JAB Sep 20 '16 at 17:28
  • @JAB — is that a nudge to update my answer? :) – Will Robertson Oct 4 '16 at 7:06

At the risk of beating a dead horse, I find the framed package works most convenient.

   My long text that needs new lines.

You need not worry about sizing--line breaks are automatic. It works well with the beamer class too.

  • 3
    G'on and beat the horse. This helped me. – Geoff Jun 21 '14 at 19:16
  • Same here, because I can't use mdframed because of a conflict. – magu_ Dec 3 '15 at 22:56

If you dig through the chain of macro expansions, you see that \framebox(x,y)[z]{text} ends up typesetting text in an \hbox.

So you can use this.

    \parbox{115\unitlength}{R-Sq:\\For example}%

Where all I've done is put the input inside an appropriately sized \parbox.

  • Thanks for the suggestion. I tried this and it worked perfectly. (As the text is right against the framebox line, I chose a slightly smaller size (110)) – celenius Jan 11 '11 at 2:12

enter image description here


@celenius One way to insert a newline in a framed box using \\ (\newline itself does not work with this method), using just the amsmath package and without defining a parbox, is to use boxed with array. For example:

\textrm{short line}\\
\textrm{long line containing a relatively large number of characters}\\
\textrm{short line again}

it works fine

    \parbox{\columnwidth-4\fboxsep}{sample text sample text sample text sample text sample text sample text sample text sample text sample text sample text sample text sample text sample text sample text sample text }
  • 1
    Why do you use -4\fboxsep and not -2\fboxsep-2\fboxrule? Also, you have some spurious spaces that add space (and might be the reason for you using -4\fboxsep to start with). – Werner Sep 30 at 5:26
  • when I use -4\fboxsep. It works perfectly, but -2\fboxsep-2\fboxrule can't. I don't know why but only have the result... – Sailist Oct 9 at 4:52
  • Are you including calc? – Werner Oct 9 at 5:18
  • No.. And only minted package can have the results, I just try it, it's amazing... – Sailist Oct 15 at 10:16

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.