2

I have a custom environment that I use as follows:

\documentclass[12pt,draft]{memoir}
\usepackage[dvipsnames,usenames]{color}
\definecolor{shadecolor}{gray}{0.85}

\newenvironment{Myenv}
    {\begin{adjustwidth}{1in}{1in}\indent\begin{qshade}}
    {\end{qshade}\end{adjustwidth}}


\begin{document}
TESTTESTTESTTEST.  MORE TEXT.
\begin{Myenv}
Lots and lots of text \par
Including multiple lines and paragraphs.
\end{Myenv}
\end{document}

With this definition I DO get my first paragraph inside the shaded square indented. HOWEVER, I seem to get some extra 'ghost' space, so that the first paragraph in the text is subtly extra indented. AND in addition \indent seems to also add an extra blank line right before the shaded environment.

Any ideas on how to fix the environment?

P.S. I am deliberately NOT using the minipage environment because it doesn't break across pages. qshade from the memoir package DOES break across pages.

UPDATE

Thanks to John Kormylo below for the code that replaces \indent: namely, replacing the first line of my environment definition by

{\begin{adjustwidth}{1in}{1in}\begin{qshade}\hspace{\parindent}}.

Thank you everyone else that advised me not to use \indent.

The new code gets rid of the extra blank line that \indent was fabricating. HOWEVER, the small extra space at the beginning of the first paragraph still shows up. Obviously \indent is not the culprit of that subtle extra indentation.

  • Please provide a complete small document we can compile to reproduce. That is much more useful than a few fragments of code. In order to work on this, somebody has to start guessing all kinds of things they cannot possibly know e.g. how qshade is defined etc. – cfr Dec 1 '15 at 5:05
  • It is almost never a good idea to use \indent or \noindent in an environment definition but the exact interaction of course depends on the definition of the environments that you have not shown. You could avoid the space by using \ignorespaces but not using \indent is almost always better, – David Carlisle Dec 1 '15 at 8:02
  • 1
    And there is always \hspace{\parindent}. – John Kormylo Dec 1 '15 at 14:23
  • @JohnKormylo: Your suggestion works wonders for removing the extra blank line... The extra space in the first paragraph is still there though... – ltcomdata Dec 2 '15 at 0:53
2

You can use \hspace*{\parindent} to insert a forced paragraph indent on the first line of the first paragraph. Secondly, in order to get rid (or ignore) any additional spurious spaces, add \ignorespaces to the opening definition of Myenv:

enter image description here

\documentclass{memoir}
\usepackage[dvipsnames,usenames]{color}
\definecolor{shadecolor}{gray}{0.85}

\newenvironment{Myenv}
  {\begin{adjustwidth}{1in}{1in}%
   \begin{qshade}\hspace{\parindent}\ignorespaces}
  {\end{qshade}%
   \end{adjustwidth}}

\begin{document}
Lots and lots of text \par
Including multiple lines and paragraphs.
\begin{Myenv}
Lots and lots of text \par
Including multiple lines and paragraphs.
\end{Myenv}
Lots and lots of text \par
Including multiple lines and paragraphs.
\end{document}

As mentioned spurious spaces may be inserted at the start of the Myenv environment. To remove this effect manually, remove \ignorespaces and use

\begin{Myenv}%

Note the use of %, as suggested by What is the use of percent signs (%) at the end of lines?

| improve this answer | |
0

Edit: Now, when is more clear, what you like to have, try the following:

\documentclass[12pt,draft]{memoir}
    \usepackage[dvipsnames,usenames]{color}
    \usepackage[many]{tcolorbox}

    \usepackage{lipsum}

\newlength\MyIndent
\setlength\MyIndent{\parindent}
\newtcolorbox{Myenvbox}{%
        enhanced,
        arc=0mm,
        frame hidden,
        colback=gray!30,
            grow to left by =-1in,
            grow to right by=-1in,
        breakable}
\newenvironment{Myenv}
    {\begin{Myenvbox}\setlength\parindent{\MyIndent}}
    {\end{Myenvbox}}

    \begin{document}
\lipsum[1-3]

     \begin{Myenv}
\lipsum[2]\par
\lipsum[2]
    \end{Myenv}
    \end{document}

enter image description here

| improve this answer | |
  • Thank you for your answer. I considered using the minipage environment in my definition. I decided against it because it doesn't break across pages, whereas the qshade environment from memoir does. – ltcomdata Dec 2 '15 at 2:33
  • This you not mentioned in your question ... how do I know then? – Zarko Dec 2 '15 at 3:40
  • @ltcomdata, see, if new version of my answer fit your wishes. – Zarko Dec 2 '15 at 4:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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