Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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?

share|improve this question
add comment

5 Answers 5

up vote 6 down vote accepted

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:

\usepackage{minibox}
...
\framebox(115,115){\minibox{R-Sq:\\ For example}}

A ‘minibox’ is exactly equivalent to a tabular in the current implementation; I just wanted the shorter markup. I've considered adding frames to the minibox package but haven't had the chance to look at it yet.

share|improve this answer
    
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
add comment

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.

\documentclass{article}
\begin{document}
\framebox(115,115){%
    \parbox{115\unitlength}{R-Sq:\\For example}%
}
\end{document}

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

share|improve this answer
    
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
add comment

@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:

\documentclass[11pt]{article}
\usepackage{amsmath}
\begin{document}
\boxed{
\begin{array}{clr}
\textrm{short line}\\
\textrm{long line containing a relatively large number of characters}\\
\textrm{short line again}
\end{array}}
\end{document}
share|improve this answer
add comment

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

\usepackage{framed}
\begin{framed}
   My long text that needs new lines.
\end{framed}

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

share|improve this answer
    
G'on and beat the horse. This helped me. –  Geoff Jun 21 at 19:16
add comment
\documentclass{article}
\usepackage[usestackEOL]{stackengine}
\begin{document}
\framebox{\Longstack[l]{This\\is\\a\\test}}
\framebox{\Longstack[c]{This\\is\\a\\test}}
\framebox{\Longstack[r]{This\\is\\a\\test}}
\end{document} 

enter image description here

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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