GeneralPlace image on the left margin

LaTeX specific issues not fitting into one of the other forums of this category.
phi
Posts: 577
Joined: Tue Oct 21, 2008 8:10 pm

Place image on the left margin

Post by phi »

-Robin- wrote:The shaded paragraph is in my example put on page 2, while the margin note stays on page 1
Not on my system; perhaps we have different versions for some packages. Anyway, try the following:

Code: Select all

\newenvironment{warnpar}{\shaded\leavevmode\marginnote{test}\ignorespaces}{\endshaded}
And please, don't add spaces or newlines at random places in command or environment definitions—they are not ignored!

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

-Robin-
Posts: 31
Joined: Tue May 20, 2008 3:07 pm

Re: Place image on the left margin

Post by -Robin- »

Thanks, that last command works likes a charm.
Now I'm going to google a bit to see what those extra commands are actually doing.

And thanks for the tip of removing those newlines / spaces from the commands/environments definitions. This is all pretty new to me, hence the (sometimes rather stupid) errors
phi
Posts: 577
Joined: Tue Oct 21, 2008 8:10 pm

Place image on the left margin

Post by phi »

-Robin- wrote:Now I'm going to google a bit to see what those extra commands are actually doing.
\leavevmode forces a paragraph start by leaving vertical mode (this should be described in some manual). \ignorespaces ignores all spaces after the environment (which doesn't really change anything here because we are at the start of a paragraph).
And thanks for the tip of removing those newlines / spaces from the commands/environments definitions.
\begin{X} ... \end{X} is basically equivalent to \begingroup\beginX ... \endX\endgroup. It is quite common to wrap an environment in another one, and then the inner group is unnecessary (but not harmful). The replacement texts of \beginX and \endX are inserted without any changes, and if they contain line breaks or spaces, those will be visible in the output—a single line break is the same as a space from TeX's point of view. This is why you got the space in your first code. You can either put the whole definition in one line, or mask every line break inside the definition by commenting it out:

Code: Select all

\newcommand{\XYZ}{XYZ}
% or
\newcommand{\XYZ}{%
  X%
  Y%
  Z%
}
When you open a package or class file, you see lines like this all over the place.
-Robin-
Posts: 31
Joined: Tue May 20, 2008 3:07 pm

Re: Place image on the left margin

Post by -Robin- »

Thanks again, I'll keep it in mind next time I make a new environment
Post Reply