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?
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:
\usepackage{minibox}
...
\minibox[frame]{R-Sq:\\ For example}
A ‘minibox’ is exactly equivalent to a tabular in the current implementation; I just wanted the shorter markup.
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.
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.
\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}

@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}
Put a minipage into a framebox:
\documentclass[a4paper,12pt]{article}
\begin{document}
some text
\noindent
\framebox[\textwidth] % width of the framebox
{
\begin{minipage}{0.9\textwidth} % width of the minipage
first line
second line
\end{minipage}
}
some text
\end{document}
it works fine
\framebox{
\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 }
}
-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 '19 at 05:26
-4\fboxsep. It works perfectly, but -2\fboxsep-2\fboxrule can't. I don't know why but only have the result...
– Sailist
Oct 09 '19 at 04:52
minted package can have the results, I just try it, it's amazing...
– Sailist
Oct 15 '19 at 10:16
\minibox[c]if that helps. – Will Robertson Jan 11 '11 at 02:18\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 06:36\miniboxeven has aframeargument, nice. – JAB Sep 20 '16 at 17:28