我正在使用该\fbox
命令来框住一大块文本:
\fbox{Four score and seven years ago our fathers brought forth on this continent, a new nation, conceived in Liberty, and dedicated to the proposition that all men are created equal.}
此文本不会换行。它只是超出页面范围。为什么会这样?
答案1
mdframed
我认为使用处理换行和分页的包可能会更好。
请参阅下面的 MWE 和文档以获取更详细的示例
\documentclass{article}
\usepackage{mdframed}
\begin{document}
\begin{mdframed}
Four score and seven years ago our fathers brought forth
on this continent, a new nation, conceived in Liberty, and dedicated to the proposition that all men are created equal.
\end{mdframed}
\end{document}
答案2
您可以使用\parbox
以下方式作为内容:
如果您不关心我通常使用的精确尺寸:
\fbox{\parbox{0.90\linewidth}{...}}
如果您希望文本仍然占据整个行宽并进入
\fbox
边距,那么您可以使用@Werner 的建议:\noindent\makebox[\linewidth][l]{\hspace{\dimexpr-\fboxsep-\fboxrule\relax}\fbox{\parbox{\linewidth}{...}}}
如果您希望
\fbox
保持在边距边界内,可以使用:\noindent\fbox{\parbox{\dimexpr\linewidth-2\fboxsep-\fboxrule\relax}{...}}
[showframe]
以下是我使用以下选项的结果包裹geometry
显示边距:
笔记:
- 如果你不介意添加其他软件包,我个人建议使用包裹
mdframed
或者adjustbox
包裹解决方案发布在这里。
代码:
\documentclass{article}
\usepackage{xcolor}
\usepackage[showframe]{geometry}
\newcommand{\FboxText}{Four score and seven years ago our fathers brought forth on this continent, a new nation, conceived in Liberty, and dedicated to the proposition that all men are created equal.}
\begin{document}
\fbox{\parbox{0.90\linewidth}{\FboxText}}
\bigskip
\noindent\makebox[\linewidth][l]{\hspace{\dimexpr-\fboxsep-\fboxrule\relax}\fbox{\parbox{\linewidth}{\FboxText}}}
\bigskip
\noindent\fbox{\parbox{\dimexpr\linewidth-2\fboxsep-\fboxrule\relax}{\FboxText}}
\end{document}
答案3
如果您不希望框架文本跨页面,您可以使用adjustbox
以下包:
\documentclass{article}
\usepackage{adjustbox}
\begin{document}
\adjustbox{minipage=\linewidth-2\fboxsep-2\fboxrule,fbox}{Four score and seven years ago our fathers brought forth on this continent, a new nation, conceived in Liberty, and dedicated to the proposition that all men are created equal.}
\end{document}
这会将内容放置在minipage
当前行宽减去框架所需空间的环境中。如果您希望文本与普通文本一样宽,并且框架应该进入边距,请使用\adjustbox{minipage=\linewidth,fbox,center}{..}
。
当然,如果您不想加载其他包,也可以手动使用合适的包,但这样minipage
可以让 live 更加轻松。查看手册以了解更多有用的键。\fbox
adjustbox