Text FormattingNewcommand works but newenvironment fails to wrapfig

Information and discussion about LaTeX's general text formatting features (e.g. bold, italic, enumerations, ...)
Post Reply
yiorgosb
Posts: 30
Joined: Mon Aug 02, 2010 11:56 pm

Newcommand works but newenvironment fails to wrapfig

Post by yiorgosb »

I place this topic here since it is in essence a formatting issue.
I've created a newenvironment for wrapping a figure but it fails to wrap text (text overlaps figure). When I place the same code to a newcommand everything works fine and I can't figure out why.
I quote the two code excerpts below.

New envrironment

Code: Select all

\newenvironment{yfifg}[1][] { 

\begin{wrapfigure}{r}{0.2\textwidth}
		 \begin{center}
		    \includegraphics[width=0.18\textwidth]{images/c\thechapter /\thecntfig}
		 \end{center}
		 \caption{#1}
	\end{wrapfigure} 

	\stepcounter{cntfig}} {}
New command

Code: Select all

\newcommand{\yfig}[1]{ 

\begin{wrapfigure}{r}{0.2\textwidth}

		 \begin{center}

		    \includegraphics[width=0.18\textwidth]{images/c\thechapter /\thecntfig}

		 \end{center}

		 \caption{#1}

	\end{wrapfigure}}
Obviously in text they are called as

Code: Select all

\begin{yfifg} {acaption} \end{yfifg}
and
\fig{acaption}
respectively.


PS: (A simple question for not open a new topic) both environment and command may accept only one default value?

Recommended reading 2024:

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

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

And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p

Post Reply