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:

\documentclass[12pt,a4paper]{article}
\newcounter{conto}
\setcounter{conto}{\time}
\usepackage{lmodern}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{dsfont}
\usepackage{mathrsfs}
\usepackage{amssymb,amsmath}
\usepackage{cancel}
\begin{document}
\section{Prove}
\(\boxed{1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20"a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z"}\)
\end{document}

but the output is the following:

enter image description here

How start a new line in \boxed{} automatically?

share|improve this question
    
"bondex", lapsus linguae!.. thanks egreg! :) –  mle Mar 15 at 22:18
1  
Nothing is display mode has automatic line breaks. You have to use \parbox. –  John Kormylo Mar 15 at 22:51
    
@JohnKormylo, How to use \parbox? –  mle Mar 15 at 22:55
add comment

4 Answers 4

up vote 5 down vote accepted

Good evening, the \boxed command is defined in the amsmath.{sty|dtx} file (that's a part of the amsmath bundle), it's:

\newcommand{\boxed}[1]{\fbox{\m@th$\displaystyle#1$}}

We can redefine it and use inline mathematics instead. With the help of \fbox command we can draw a rectangle, the proper width is \textwidth-2\fboxrule-2\fboxsep. The core of our work is to allow lines break at proper places (commas, quotation marks) without losing them, let's use \allowbreak for this purpose.

The fast trick is to make those characters active (\catcode to 13) and define them to our desire. The only problem in our example is not get ourselves in an infinite loop, therefore we store original characters before activation in separate commands.

We usually do all this in a group, e.g. by using { }, I'm skipping this step.

And voilà! I enclose a small example. Enjoy! :-)

\documentclass[12pt,a4paper]{article}
\usepackage{amsmath}
\begin{document}
% \the\fboxrule % If we wish to see the first used dimension...
% \the\fboxsep  % If we wish to check the second used dimension...
% E.g., we wish to have a nice cozy rectangle across the whole mirror...
\parindent=0pt
% One paragraph typeset for checking purposes only...
text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text\par
% Let's compute the real width of the mirror...
\newdimen\temp                % A declaration of a new dimension...
\temp=\textwidth              % The width of the text minus
\advance\temp by -2\fboxrule  %    border from both sides minus
\advance\temp by -2\fboxsep   %    inner separator from both sides.
% Storage of the \boxed command created by the AMS... (amsmath.dtx).
\let\oldboxed=\boxed
% Redefinition of \boxed, let's use breakable inline mathematics...
\def\boxed#1{\fbox{\parbox{\temp}{$#1$}}}
% We'll make comma as an active character according to our wishes...
\def\mycomma{,}
\catcode`\,=13
\def,{\mycomma\allowbreak}
% The same strategy will be applied to one more used character...
\def\mymark{"}
\catcode`\"=13
\def"{\mymark\allowbreak}
% The core of our efforts...
\boxed{1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20"a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z"}\par
% And we are back in reality from our dreams... ;-)
\let\boxed=\oldboxed
\boxed{1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20"a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z"}
\end{document}

enter image description here

I have only added \pagestyle{empty} in the preamble of the document to get a proper cropped version. If we prefer a non-mathematical version, please change $#1$ to just #1 in the redefinition of the \boxed command.

share|improve this answer
add comment

I'm not sure if you're misusing math mode; within \boxed you can use any of the “inner” amsmath environments, in this case I used aligned:

\documentclass[12pt,a4paper]{article}
\usepackage{amsmath}
\begin{document}
\[
\boxed{
  \!\begin{aligned}
  &1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,\\
  &a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z
  \end{aligned}
}
\]
\end{document}

enter image description here

Please, be more precise if math mode was not what you had in mind.

share|improve this answer
add comment

It also helps to add a blank.

\documentclass[12pt,a4paper]{article}
\newcounter{conto}
\setcounter{conto}{\time}
%\usepackage{lmodern}
%\usepackage[T1]{fontenc}
%\usepackage[utf8]{inputenc}
%\usepackage{dsfont}
%\usepackage{mathrsfs}
\usepackage{amssymb,amsmath}
%\usepackage{cancel}
\begin{document}
\section{Prove}
\(
\fbox{\parbox{4in}{1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20 "a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z"}}
\)
\end{document}

boxed

I should mention that inside the \parbox you are no longer in math mode.

share|improve this answer
add comment

You can use a stack. Note that the default end-of-line (EOL) character is a space in stackengine's \Longstack, which works just fine for your example. But often, if your stack contains natural spaces, then you need to change the EOL for the stack, which I do for the second stack, to \\, using \setstackEOL{}. Also, the use of \stackMath or \stackText will cause the stacking arguments to be interpreted as math or text, respectively, as I also show.

\documentclass[12pt,a4paper]{article}
\newcounter{conto}
\setcounter{conto}{\time}
\usepackage{lmodern}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{dsfont}
\usepackage{mathrsfs}
\usepackage{amssymb,amsmath}
\usepackage{cancel}
\usepackage{stackengine}

\begin{document}
\section{Prove}
\stackMath
\(\boxed{\Longstack{1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20
``a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z''}}\)
\section{Prove Again}
\setstackEOL{\\}
\stackText
\(\boxed{\Longstack{1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20\\
``a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z''}}\)
\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.