如何插入可控制边距的文本框

如何插入可控制边距的文本框

我想插入一个可控制边距的文本框。具体来说,如何将下面的文本格式化为下图所示?以及如何设置间距?目前,我使用的是

\noindent\fbox{
    \parbox{0.97\columnwidth}{
        \textbf{Finding 3:} the text  \\
        \textbf{Implication:} the text 
    }
}

但空间几乎为0。

文本:

大部分行级故障都是由于数据异常导致的。由于异常数据不可预测,程序员可以利用领域知识主动编写异常数据处理代码来帮助减少故障,这与防御性编程的理念类似。

发现 3:行级故障很普遍(62.0%)。其中大多数是由异常数据引起的。程序员无法提前知道所有异常数据。含义:利用领域知识主动编写异常数据处理代码有助于减少行级故障。

如何修复故障与导致故障的原因息息相关。对于大多数故障类别,都存在修复模式。这些模式下的修复在代码行数上非常少。在样本集 A 中,95.0% 的修复在 10 行以内,87.0% 的修复在 5 行以内;修复的平均大小为 3.5 行。此外,行过滤、无效性检查和资源导入等修复模式通常不涉及程序语义。因此,基于这些模式可以自动生成一些修复建议,帮助程序员修复相应的缺陷。

enter image description here

答案1

您可以使用framed包。框架和内部文本之间的间距由长度控制FrameSep\FrameOuterSep是周围文本和框架之间的垂直间距。当然,框架和背景可以着色,其厚度可以改变(它是长度FrameRule),最重要的是,它可以跨页面:

\documentclass[a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{erewhon}
\usepackage{geometry}
\usepackage{framed}
\setlength\FrameSep{0.5em}
\setlength\OuterFrameSep{\partopsep}
\begin{document}

Most of \emph{row-level} failures are due to exceptional data. Since the exceptional data are unforeseeable, programmers could proactively write exceptional-data-handling code with domain knowledge to help reduce failures, sharing the similar philosophy with the defensive programming.

\begin{framed}\noindent
  \textbf{Finding 3:} Row-level failures are prevalent (62.0\,\%). Most of them are caused by exceptional data. Programmers cannot know all of exceptional data in advance. \\
  \textbf{Implication:} Proactively writing exceptional-data-handling code with domain knowledge could help reduce row-level failures.
\end{framed}

How to fix the failures is closely related to the reasons that cause the failures. For most failure categories, there exist fix patterns. Fixes under these patterns are very small in terms of LOC. In Sample Set A, 95.0\,\% fixes are within 10 LOC and 87.0\,\% fixes are within 5 LOC; the average size of fixes is 3.5 LOC. In addition, fix patterns such as row filtering, nullity checking, and resources import, usually do not involve program semantics. Hence, based on these patterns, it is possible to automatically generate some fix suggestions to help programmers fix corresponding defects.


\end{document} 

enter image description here

答案2

由和或选项tcolorbox控制边距参数的解决方案。leftboxsepright

稍后可以通过将规范作为环境的可选参数来更改边距somebox

\%我特意把留在第二个框中,以显示更好的间距siunitx(第一个例子)

\documentclass[twocolumn]{article}

\usepackage{tcolorbox}


\usepackage{siunitx}

\newtcolorbox[auto counter]{somebox}[1][]{arc=0pt,auto outer arc,left=1pt,boxsep=1pt,boxrule=1pt,width=\columnwidth,right=1pt,#1}

\usepackage{blindtext}

\begin{document}


Most of \emph{row-level} failures are due to exceptional data. Since the exceptional data are unforeseeable, programmers could proactively write exceptional-data-handling code with domain knowledge to help reduce failures, sharing the similar philosophy with the defensive programming.
\begin{somebox}
\textbf{Finding 3:} Row-level failures are prevalent (\SI{62.0}{\percent}). Most of them are caused by exceptional data. Programmers cannot know all of exceptional data in advance. 

\textbf{Implication:} Proactively writing exceptional-data-handling code with domain knowledge could help reduce row-level failures.the text 
\end{somebox}

\begin{somebox}[left=5pt]
  \textbf{Finding 3:} Row-level failures are prevalent (62.0\%). Most of them are caused by exceptional data. Programmers cannot know all of exceptional data in advance. 

  \textbf{Implication:} Proactively writing exceptional-data-handling code with domain knowledge could help reduce row-level failures.the text 

\end{somebox}


\end{document}

enter image description here

相关内容