如何在任意大段的文字/图形/其他内容周围绘制一个框架?

如何在任意大段的文字/图形/其他内容周围绘制一个框架?

该命令fbox{...}可用于在一段文本周围绘制一个框,显然也可以绘制一个图形。但是,如果“文本”包含 minipages 和 center 等环境,我就无法使用它。

那么,如何在包含不仅仅是文本(例如图形、表格、环境等)的任意文本周围绘制一个框?

答案1

使用包mdframed,它还支持分页符

\documentclass{article}

\usepackage[linewidth=1pt]{mdframed}
\usepackage{lipsum}

\begin{document}
\lipsum[2]

\begin{mdframed}
\lipsum[2]
\end{mdframed}

\lipsum[2]

\begin{mdframed}[leftmargin=10pt,rightmargin=10pt]
\lipsum[2]
\end{mdframed}

\lipsum[2]

\begin{mdframed}[leftmargin=-10pt,rightmargin=-10pt]
\lipsum[2]
\end{mdframed}

\end{document}

答案2

虽然这是一个老问题,但没有一个答案提到tcolorbox为带有标题行的彩色和框架文本框提供环境

它声明了一个环境,tcolorbox用于构建默认占据行宽的彩色框。这些框可以完全自定义,允许分页,并且可以包含任何类型的文本(常规段落、小页面、表格、数学等)。一些小例子如下:

\documentclass{article}
\usepackage{lipsum}
\usepackage{lmodern}
\usepackage{tcolorbox}

\begin{document}
\lipsum[2]

\begin{tcolorbox}
\lipsum[3]
\end{tcolorbox}

\begin{tcolorbox}[sharp corners, colback=green!30, colframe=green!80!blue, title=Another paragraph with title]
\lipsum[2]
\end{tcolorbox}

\begin{tcolorbox}[width=6cm]
I'm sure you know that 
\[
\sin^2 x + \cos^2 = 1
\]
Don't you?
\end{tcolorbox}

\end{document}

在此处输入图片描述

tcolorbox软件包还提供了根据内容构建盒子的命令\tcbox。这种盒子是不可破坏的。

\documentclass{article}
\usepackage{lipsum}
\usepackage{lmodern}
\usepackage{tcolorbox}

\begin{document}

\tcbox{This is a sentence}

\tcbox[colback=blue!30, colframe=blue!30!black]{\begin{tabular}{cc}A & B \\ C & d\end{tabular}}

\tcbox[sharp corners, colframe=red, colback=red!20!blue!30]{\includegraphics[width=4cm]{example-image-A}}

\end{document}

在此处输入图片描述

tcolorbox有关其所有功能的信息可以在氯化三乙胺

答案3

您需要\parbox在里面使用或类似的东西\fbox来处理不起作用的项目例如

\documentclass{article}
\usepackage{lipsum}
\begin{document}
\fbox{%
  \parbox{\textwidth}{%
    \begin{center}
      \lipsum[1-3]
    \end{center}
  }%
}
\end{document}

但对于minipage情况来说,一切正常:

\documentclass{article}
\usepackage{lipsum}

\begin{document}
\fbox{%
  \begin{minipage}{\textwidth}
    \lipsum[1-3]
  \end{minipage}
}
\end{document}

(这lipsum这里的包纯粹用于提供填充文本:解决方案不需要它。)

答案4

这是一个使用eplain的例子:

\input eplain
\vsize=4.3in
\boxit{\halign{&\tabskip1em#\hfil\cr Some stuff & in a table & just to show \cr
  \noalign{\smallskip\hrule\smallskip}
  the frame & around the table \cr}}
\smallskip
\boxit{\vbox{\hsize=2in% just to keep the image smaller
  Lorem ipsum dolor sit amet. This could go on and on and on until we hit the
  edge of the page at which point there should be automatically another line}}
\smallskip \boxitspace=2em
\boxit{\vbox{\hsize=2in\item{1.} A list \item{2.} With list items
  \item{3.} And 2em padding}}
\smallskip \boxitspace=5pt
\boxit{\XeTeXpicfile "test-pattern.jpg"}
\footline={\boxit{\hbox{\tenrm\folio}}\hss}
\bye
% the boxit macro from eplain for completeness
% modified for stand-alone use (ehrule to hrule; evrule to vrule)
\newdimen\boxitspace \boxitspace = 3pt
\long\def\boxit#1{%
  \vbox{%
    \hrule
    \hbox{%
      \vrule
      \kern\boxitspace
      \vbox{\kern\boxitspace \parindent = 0pt #1\kern\boxitspace}%
      \kern\boxitspace
      \vrule
    }%
    \hrule
  }%
}%

在此处输入图片描述

相关内容