在文本后面获取彩色矩形的最简单方法?

在文本后面获取彩色矩形的最简单方法?

我想在文本后面显示一个灰色矩形,这样文本的某些部分就更容易识别。我会这样做来突出显示问题的主体。

我找到了各种各样的包,比如fancytooltips或者,tcolorbox但我觉得它们对于我想要实现的目标来说太复杂了。

理想情况下,它应该是一个简单的灰色矩形,就像你在 Math.SE 上添加引号时得到的那样:

盒子

特殊的左边框甚至没有必要。实现此目的的最简单方法是什么?

答案1

shaded具有包环境的解决方案framed

\documentclass{article}
\usepackage[svgnames]{xcolor}
\usepackage{framed}

\definecolor{shadecolor}{named}{LightGray}

\begin{document}
    Wikipedia claims
    \begin{shaded}
        \noindent The fundamental theorem of a field of mathematics is the theorem considered central to that field. The naming of such a theorem is not necessarily based on how often it is used or the difficulty of its proofs.
    \end{shaded}
    So I am left wondering: what \emph{is} the main criterion for a theorem to be considered fundamental?
\end{document}

在此处输入图片描述

另一个带有内部环境的示例theorem

\documentclass{article}
\usepackage{amsthm}
\usepackage[svgnames]{xcolor}
\usepackage{framed}

\theoremstyle{definition}
\newtheorem{mythm}{Theorem}
\definecolor{shadecolor}{named}{LightGray}

\begin{document}
    Wikipedia claims
    \begin{shaded}
        \begin{mythm}
            The fundamental theorem of a field of mathematics is the theorem considered central to that field. The naming of such a theorem is not necessarily based on how often it is used or the difficulty of its proofs.
        \end{mythm}
    \end{shaded}
    So I am left wondering: what \emph{is} the main criterion for a theorem to be considered fundamental?
\end{document}

在此处输入图片描述

答案2

与 David 的相同,但更精致,并带有图片 ;-)

\documentclass{article}
\usepackage{xcolor}
\usepackage{lipsum}
\newcommand{\highlight}[1]{%
 \par\noindent
 \colorbox{gray!30}{%
 \parbox{\dimexpr\linewidth-2\fboxsep\relax}{%
 #1
 }%
 }}

\begin{document}
  \lipsum[1]
  \highlight{\lipsum*[1]}
\end{document}

在此处输入图片描述

但我不同意你的观点,因为这tcolorbox很复杂。请看下面的例子。

\documentclass{article}
\usepackage{tcolorbox}
\usepackage{lipsum}
\newtcolorbox{mybox}{colback=gray!30,
boxrule=0pt,arc=0pt,boxsep=2pt,left=2pt,right=2pt,leftrule=1pt}

\begin{document}
  \lipsum[1]
  \begin{mybox}
    \lipsum*[1]
  \end{mybox}
\end{document}

在此处输入图片描述

答案3

color包装和

\colorbox[gray]{0.5}{\parbox{.7\textwidth}{The fundamental......}}

相关内容