如何在 \boxed{} 開始新行?

如何在 \boxed{} 開始新行?

我有:

\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}

但輸出如下:

在此輸入影像描述

如何自動開始新行\boxed{}

答案1

晚上好,該\boxed命令在文件中定義amsmath.{sty|dtx}(這是捆綁包的一部分amsmath),它是:

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

我們可以重新定義它並使用內聯數學代替。借助\fbox指令我們可以畫一個矩形,適當的寬度是\textwidth-2\fboxrule-2\fboxsep。我們工作的核心是允許在適當的位置(逗號、引號)換行而不丟失它們,讓我們用於\allowbreak此目的。

快速的技巧是使這些角色活躍(\catcode13)並根據我們的願望定義它們。我們的範例中唯一的問題是不會陷入無限循環,因此我們在啟動之前將原始字元儲存在單獨的命令中。

我們通常在一個小組中完成所有這些,例如通過使用{ },我跳過這一步。

瞧!我附上一個小例子。享受! :-)

\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}

在此輸入影像描述

\pagestyle{empty}我僅在文件的序言中添加了內容以獲得正確的裁剪版本。如果我們更喜歡非數學版本,請在命令的重新定義中更改$#1$為僅。#1\boxed

答案2

我不確定你是否誤用了數學模式;在\boxed你可以使用任何「內部」amsmath環境,在本例中我使用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}

在此輸入影像描述

如果數學模式不是您想要的,請更精確。

答案3

添加空白也有幫助。

\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}

盒裝的

我應該要提到的是,在 \parbox 中你不再處於數學模式。

答案4

您可以使用堆疊。請注意,預設的行結束符 (EOL) 是stackengines中的空格\Longstack,這對於您的範例來說效果很好。但通常,如果您的堆疊包含自然空格,那麼您需要使用 將該堆疊的 EOL 更改為 ,我對第二個堆疊執行此\\操作\setstackEOL{}。此外,使用\stackMathor\stackText會導致堆疊參數分別被解釋為數學或文本,正如我所展示的。

\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}

在此輸入影像描述

相關內容