Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I'm writing my thesis and I want to highlight some part of my text which resides in a separate paragraph. I like the well-known example of

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

and then

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

But if the sentence is very long (more than one line) the result is not good looking at all, e.g.

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

I'm wondering how I can keep the margins (left and right), repeat the square every line and.. make it bold (or with a gray background).

Thanks for any help Alex PS: This is my first post so I hope it's good

share|improve this question
add comment

1 Answer

You can adapt an answer of mine:

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

enter image description here

share|improve this answer
    
I tried to adapt the quote code, but I found it really difficult and complicated. More than copy-paste I don't know what to do, for example to make the text of the environment bold. –  Alex Jul 31 '12 at 15:14
    
@Alex If you want to make all the text bold, just add \bfseries after \centering before \BODY: \BODY stands for the environment's content. –  egreg Jul 31 '12 at 16:28
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.