新环境。使用符号和缩进突出显示内容

新环境。使用符号和缩进突出显示内容

我正在写论文,我想突出显示文本中位于单独段落中的部分内容。我喜欢这个众所周知的例子

\newenvironment{king}
{\rule{1ex}{1ex}\hspace{\stretch{1}}}
{\hspace{\stretch{1}}\rule{1ex}{1ex}}

进而

\begin{king}
My humble subjects \ldots
\end{king}

但是如果句子很长(超过一行),结果看起来就不太好看,例如

\begin{king}
Energy is the property of matter and radiation that is manifest as a capacity to perform work.
\end{king}

我想知道如何保持边距(左和右),每行重复正方形并使其变为粗体(或使用灰色背景)。

感谢 Alex 的帮助 PS:这是我的第一篇文章,希望它能写得好

答案1

你可以适应我的答案

\documentclass{article}
\usepackage{environ}
\usepackage{lipsum}

\makeatletter
\newif\ifboxended
\def\centervbox#1{\begingroup\global\setbox\@ne=\box\voidb@x
  \global\boxendedfalse
  \setbox\z@=\copy#1\relax\docentervbox}
\def\docentervbox{%
  \setbox\z@=\vbox{\unvbox\z@ 
    \ifcase\lastnodetype
% char node (can't remove)
    \or
% hlist node
    \setbox\tw@=\lastbox
    \def\next{%
      \global\setbox\@ne=\vbox{
        \hbox to\hsize{\rule{1ex}{1ex}\hfil\box\tw@\hfil\rule{1ex}{1ex}}\unvbox\@ne}}%
    \or
% vlist node
    \setbox\tw@=\lastbox
    \def\next{%
      \global\setbox\@ne=\vbox{
        \hbox to\hsize{\rule{1ex}{1ex}\hfil\box\tw@\hfil\rule{1ex}{1ex}}\unvbox\@ne}}%
    \or
% rule node (can't remove)
    \or
% ins node (can't remove)
    \or
% mark node (can't remove)
    \or
% adjust node (can't remove)
    \or
% ligature node (can't happen)
    \or
% disc node (can't happen)
    \or
% whatsit node (can't remove)
    \or
% math node (can't remove)
    \or
% glue node
    \skip@=\lastskip\unskip
    \def\next{\global\setbox\@ne=\vbox{\vskip\skip@\unvbox\@ne}}%
    \or
% kern node
    \dimen@=\lastkern\unkern
    \def\next{\global\setbox\@ne=\vbox{\kern\dimen@\unvbox\@ne}}%
    \or
% penalty node
    \count@=\lastpenalty\unpenalty
    \def\next{\global\setbox\@ne=\vbox{\penalty\count@\unvbox\@ne}}%
    \or
% unset node (can't happen)
    \or
% math mode node (can't remove)
    \else
% empty list
    \def\next{\global\boxendedtrue}
    \fi
    \next}
  \ifboxended
    \def\next{\unvbox\@ne\endgroup}
  \else
    \let\next\docentervbox
  \fi
  \next}
\makeatother
\NewEnviron{king}{%
  \trivlist\item\relax
  \setbox4=\vbox{\advance\hsize-4ex\centering\BODY\par}\centervbox{4}%
  \endtrivlist
}



\begin{document}

\lipsum[2]

\begin{king}
Energy is the property of matter and radiation that is manifest as a capacity to perform work.
\end{king}

\lipsum[2]

\begin{king}
My humble subjects
\end{king}

\lipsum[2]

\end{document}

在此处输入图片描述

相关内容