例如,我想将一长段文字放在一个框中
The quick brown fox jumps right over the lazy dog. the quick brown fox
jumps right over the lazy dog. the quick brown fox jumps right over the lazy
dog. the quick brown fox jumps right over the lazy dog. the quick brown fox
jumps right over the lazy dog. the quick brown fox jumps right over the lazy
dog. the quick brown fox jumps right over the lazy dog. the quick brown fox
jumps right over the lazy dog.
如何实现?有什么简短的建议吗?
答案1
您可以使用在包含文本的\fbox{...}
周围放置一个框架。这是一个示例文档。请注意可防止框向右移动。\parbox{...}
\noindent
\documentclass{article}
\begin{document}
\noindent\fbox{%
\parbox{\textwidth}{%
The quick brown fox jumps right over the lazy dog. the quick brown fox jumps right over the lazy dog. the quick brown fox jumps right over the lazy dog. the quick brown fox jumps right over the lazy dog. the quick brown fox jumps right over the lazy dog. the quick brown fox jumps right over the lazy dog. the quick brown fox jumps right over the lazy dog. the quick brown fox jumps right over the lazy dog.
}%
}
\end{document}
答案2
环境minipage
是对某事物进行装箱或分组的充分方式:
\documentclass{article}
\begin{document}
\begin{minipage}{15em}
The quick brown fox jumps right over the lazy dog. the quick brown fox
jumps right over the lazy dog. the quick brown fox jumps right over the lazy
dog. the quick brown fox jumps right over the lazy dog. the quick brown fox
jumps right over the lazy dog. the quick brown fox jumps right over the lazy
dog. the quick brown fox jumps right over the lazy dog. the quick brown fox
jumps right over the lazy dog.
\end{minipage}
\end{document}
如果你想框住它,你可以用\fbox
命令把它围起来。也就是说,
\fbox{\begin{minipage}{15em}
...
\end{minipage}}
答案3
\fbox
和minipage
或全部的解决方案\parbox
存在缺陷,即文本将是一个不可分割的对象,无法跨页面分割。对于一次性应用程序来说,这可能是可行的方法。否则,框架高度可定制的包。
\documentclass{article}
\usepackage[]{mdframed}
\begin{document}
\begin{mdframed}
Test
\end{mdframed}
\end{document}
您可以在框架文档:
https://mirror.ibcp.fr/pub/CTAN/macros/latex/contrib/mdframed/mdframed.pdf
答案4
我认为这是最好的答案https://tex.stackexchange.com/a/25926/120007, 使用mdframed
。
但之前,为了改进其他答案,我定义了一个在单列模式和双列模式下工作的新命令:
\documentclass[twocolumn]{article}
\usepackage{lipsum}
\usepackage[]{mdframed}
% draw a frame around given text
\newcommand{\framedtext}[1]{%
\par%
\noindent\fbox{%
\parbox{\dimexpr\linewidth-2\fboxsep-2\fboxrule}{#1}%
}%
}
\begin{document}
\lipsum[1]
\section{This uses mdframed}
Lorem ipsum dolor sit amet, consectetuer adipiscing
elit. Ut purus elit, vestibulum ut, placerat ac, adi-
piscing vitae, felis.
\begin{mdframed}
A long sentence with multiple words and a sample equation $e^{i\pi}+1=0$.
\end{mdframed}
Lorem ipsum dolor sit amet, consectetuer adipiscing
elit. Ut purus elit, vestibulum ut, placerat ac, adi-
piscing vitae, felis.
\section{This uses the new command}
Lorem ipsum dolor sit amet, consectetuer adipiscing
elit. Ut purus elit, vestibulum ut, placerat ac, adi-
piscing vitae, felis.
\framedtext{A long sentence with multiple words and a sample equation $e^{i\pi}+1=0$.}
\lipsum[4-7]
\end{document}
也可以看看: