如何将长段文字放入框中?

如何将长段文字放入框中?

例如,我想将一长段文字放在一个框中

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

小页面 + fbox

答案3

\fboxminipage或全部的解决方案\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}

上面的 latex 的输出

也可以看看:

相关内容