How to insert some commands before an existing environment?

  • Follow


For example, I want to insert some commands such as
\centering
and some other commands come from ccaption package before the other
commands in the figure environment,
and no need to use a new environment name.

How to implement this effect?
I've tried the following codes, but it didn't work.

\def\tempfigure\figure
\renewcommand\figure
 {\tempfigure
  \hangcaption
  \captiontitlefont{\sffamily}
  \centering}

But, the following codes do work well:
\begin{figure}
  \hangcaption
  \captiontitlefont{\sffamily}
  \centering
.....
\end{figure}
0
Reply rockyzhz (6) 12/20/2009 7:20:47 PM

In article <1080cf52-5e6f-4b78-9f6f-4d9aa19c7ecf@u18g2000pro.googlegroups.com>,
 Rocky Zhang <rockyzhz@gmail.com> writes:
>For example, I want to insert some commands such as
>\centering
>and some other commands come from ccaption package before the other
>commands in the figure environment,
>and no need to use a new environment name.
>
>How to implement this effect?
>I've tried the following codes, but it didn't work.
>
>\def\tempfigure\figure

i presume you mean

\def\tempfigure{\figure}

all (other) bets are off if you _didn't_ do that -- i can't imagine
what the diagnostics might be like.

>\renewcommand\figure
> {\tempfigure
>  \hangcaption
>  \captiontitlefont{\sffamily}
>  \centering}

\tempfigure is "just" \figure, so the first thing \figure does is to
call itself.  hence the diagnostic.

\let\tempfigure\figure

makes a "frozen" copy of \figure, which isn't changed by subsequent
redefinition, so use that instead of the (corrected) \def.

(note the confusing fact that \let doesn't want braces round its
second argument, like \def does.  this is the sort of thing you get,
dabbling in tex internals (which i presume you don't often do, from
the mistakes you've made).

>But, the following codes do work well:
>\begin{figure}
>  \hangcaption
>  \captiontitlefont{\sffamily}
>  \centering
>....
>\end{figure}

of course.
-- 
Robin Fairbairns, Cambridge
0
Reply rf10 12/20/2009 8:24:03 PM


rf10@cl.cam.ac.uk (Robin Fairbairns) writes:

> In article
> <1080cf52-5e6f-4b78-9f6f-4d9aa19c7ecf@u18g2000pro.googlegroups.com>,
> Rocky Zhang <rockyzhz@gmail.com> writes:
>>For example, I want to insert some commands such as
>>\centering
>>and some other commands come from ccaption package before the other
>>commands in the figure environment,
>>and no need to use a new environment name.
>>
>>How to implement this effect?
>>I've tried the following codes, but it didn't work.
>>
>>\def\tempfigure\figure
>
> i presume you mean
>
> \def\tempfigure{\figure}
>
> all (other) bets are off if you _didn't_ do that -- i can't imagine
> what the diagnostics might be like.

\tempfigure would be a macro that has to be called like
\tempfigure\figure\renewcommand\figure. Its expansion text is
\tempfigure\hangcaption\captiontitlefont{\sffamily} \centering. \figure
is never changed, and as long as \tempfigure doesn't appear in the
document, there is no difference at all, and no diagnostic messages.

\documentclass{article}
\def\tempfigure\figure
\renewcommand\figure
 {\tempfigure
  \hangcaption
  \captiontitlefont{\sffamily}
  \centering}
\begin{document}
\ttfamily
\meaning\figure\par
\meaning\tempfigure
\end{document}

-- 
Change “LookInSig” to “tcalveu” to answer by mail.
0
Reply Philipp 12/20/2009 8:31:40 PM

> i presume you mean
>
> \def\tempfigure{\figure}
>
> all (other) bets are off if you _didn't_ do that -- i can't imagine
> what the diagnostics might be like.
>
> \tempfigure is "just" \figure, so the first thing \figure does is to
> call itself. =A0hence the diagnostic.
>
> \let\tempfigure\figure

yeah, I changed the \def command into \let, that codes go well.
But there is still a problem that how to pass the PLACEMENT parameter
to the redefined figure environment?

I've tried some codes with PLACEMENT parameter, and then the figure(or
table) appeared at the end of document.

> makes a "frozen" copy of \figure, which isn't changed by subsequent
> redefinition, so use that instead of the (corrected) \def.
>
> (note the confusing fact that \let doesn't want braces round its
> second argument, like \def does. =A0this is the sort of thing you get,
> dabbling in tex internals (which i presume you don't often do, from
> the mistakes you've made).
>
>
> of course.
> --
> Robin Fairbairns, Cambridge

0
Reply Rocky 12/20/2009 9:10:13 PM

Rocky Zhang <rockyzhz@gmail.com> wrote:

> > i presume you mean
> >
> > \def\tempfigure{\figure}
> >
> > all (other) bets are off if you _didn't_ do that -- i can't imagine
> > what the diagnostics might be like.
> >
> > \tempfigure is "just" \figure, so the first thing \figure does is to
> > call itself. �hence the diagnostic.
> >
> > \let\tempfigure\figure
> 
> yeah, I changed the \def command into \let, that codes go well.
> But there is still a problem that how to pass the PLACEMENT parameter
> to the redefined figure environment?
> 
> I've tried some codes with PLACEMENT parameter, and then the figure(or
> table) appeared at the end of document.

\makeatletter
\g@addto@macro\@floatboxreset{%
  \hangcaption
  \captiontitlefont{\sffamily}
  \centering}
\makeatother

The macro \@floatboxreset is the last thing which is executed
before examining the floating environment's content. With that
code we supplement the definition of \@floatboxreset with the
desired commands.

But if you want every caption in that style, why not simply putting
the commands

\hangcaption
\captiontitlefont{\sffamily}

into the preamble?

Ciao
Enrico
0
Reply Enrico 12/20/2009 9:35:01 PM

On 12=E6=9C=8821=E6=97=A5, =E4=B8=8A=E5=8D=885=E6=97=B635=E5=88=86, Enrico =
Gregorio <grego...@math.unipd.it> wrote:
> Rocky Zhang <rocky...@gmail.com> wrote:
> > > i presume you mean
>
> > > \def\tempfigure{\figure}
>
> > > all (other) bets are off if you _didn't_ do that -- i can't imagine
> > > what the diagnostics might be like.
>
> > > \tempfigure is "just" \figure, so the first thing \figure does is to
> > > call itself. =C3=8Ahence the diagnostic.
>
> > > \let\tempfigure\figure
>
> > yeah, I changed the \def command into \let, that codes go well.
> > But there is still a problem that how to pass the PLACEMENT parameter
> > to the redefined figure environment?
>
> > I've tried some codes with PLACEMENT parameter, and then the figure(or
> > table) appeared at the end of document.
>
> \makeatletter
> \g@addto@macro\@floatboxreset{%
> =C2=A0 \hangcaption
> =C2=A0 \captiontitlefont{\sffamily}
> =C2=A0 \centering}
> \makeatother
>
> The macro \@floatboxreset is the last thing which is executed
> before examining the floating environment's content. With that
> code we supplement the definition of \@floatboxreset with the
> desired commands.
>
> But if you want every caption in that style, why not simply putting
> the commands
>
> \hangcaption
> \captiontitlefont{\sffamily}
>
> into the preamble?
Because I want to display the figure and table in different style.
>
> Ciao
> Enrico- =E9=9A=90=E8=97=8F=E8=A2=AB=E5=BC=95=E7=94=A8=E6=96=87=E5=AD=97 -
>
> - =E6=98=BE=E7=A4=BA=E5=BC=95=E7=94=A8=E7=9A=84=E6=96=87=E5=AD=97 -

0
Reply Rocky 12/20/2009 10:05:41 PM

Rocky Zhang <rockyzhz@gmail.com> wrote:

> On 1221, 535p, Enrico Gregorio <grego...@math.unipd.it> wrote:
> > Rocky Zhang <rocky...@gmail.com> wrote:
> > > > i presume you mean
> >
> > > > \def\tempfigure{\figure}
> >
> > > > all (other) bets are off if you _didn't_ do that -- i can't imagine
> > > > what the diagnostics might be like.
> >
> > > > \tempfigure is "just" \figure, so the first thing \figure does is to
> > > > call itself. �hence the diagnostic.
> >
> > > > \let\tempfigure\figure
> >
> > > yeah, I changed the \def command into \let, that codes go well.
> > > But there is still a problem that how to pass the PLACEMENT parameter
> > > to the redefined figure environment?
> >
> > > I've tried some codes with PLACEMENT parameter, and then the figure(or
> > > table) appeared at the end of document.
> >
> > \makeatletter
> > \g@addto@macro\@floatboxreset{%
> > � \hangcaption
> > � \captiontitlefont{\sffamily}
> > � \centering}
> > \makeatother
> >
> > The macro \@floatboxreset is the last thing which is executed
> > before examining the floating environment's content. With that
> > code we supplement the definition of \@floatboxreset with the
> > desired commands.
> >
> > But if you want every caption in that style, why not simply putting
> > the commands
> >
> > \hangcaption
> > \captiontitlefont{\sffamily}
> >
> > into the preamble?
> Because I want to display the figure and table in different style.

Use the caption package instead of ccaption.

Ciao
Enrico
0
Reply Enrico 12/20/2009 10:07:56 PM

On 12=E6=9C=8821=E6=97=A5, =E4=B8=8A=E5=8D=885=E6=97=B635=E5=88=86, Enrico =
Gregorio <grego...@math.unipd.it> wrote:
> Rocky Zhang <rocky...@gmail.com> wrote:
> > > i presume you mean
>
> > > \def\tempfigure{\figure}
>
> > > all (other) bets are off if you _didn't_ do that -- i can't imagine
> > > what the diagnostics might be like.
>
> > > \tempfigure is "just" \figure, so the first thing \figure does is to
> > > call itself. =C3=8Ahence the diagnostic.
>
> > > \let\tempfigure\figure
>
> > yeah, I changed the \def command into \let, that codes go well.
> > But there is still a problem that how to pass the PLACEMENT parameter
> > to the redefined figure environment?
>
> > I've tried some codes with PLACEMENT parameter, and then the figure(or
> > table) appeared at the end of document.
>
> \makeatletter
> \g@addto@macro\@floatboxreset{%
> =C2=A0 \hangcaption
> =C2=A0 \captiontitlefont{\sffamily}
> =C2=A0 \centering}
> \makeatother
>
> The macro \@floatboxreset is the last thing which is executed
> before examining the floating environment's content. With that
> code we supplement the definition of \@floatboxreset with the
> desired commands.
I've search the definition of \g@addto@macro, and then find it in the
"source2e".
As your codes, that would add those supplement commands into
every float environment?
> But if you want every caption in that style, why not simply putting
> the commands
>
> \hangcaption
> \captiontitlefont{\sffamily}
>
> into the preamble?
>
> Ciao
> Enrico- =E9=9A=90=E8=97=8F=E8=A2=AB=E5=BC=95=E7=94=A8=E6=96=87=E5=AD=97 -
>
> - =E6=98=BE=E7=A4=BA=E5=BC=95=E7=94=A8=E7=9A=84=E6=96=87=E5=AD=97 -

0
Reply Rocky 12/20/2009 10:36:01 PM

Rocky Zhang <rockyzhz@gmail.com> wrote:

> On 1221, 535p, Enrico Gregorio <grego...@math.unipd.it> wrote:
> > Rocky Zhang <rocky...@gmail.com> wrote:
> > > > i presume you mean
> >
> > > > \def\tempfigure{\figure}
> >
> > > > all (other) bets are off if you _didn't_ do that -- i can't imagine
> > > > what the diagnostics might be like.
> >
> > > > \tempfigure is "just" \figure, so the first thing \figure does is to
> > > > call itself. �hence the diagnostic.
> >
> > > > \let\tempfigure\figure
> >
> > > yeah, I changed the \def command into \let, that codes go well.
> > > But there is still a problem that how to pass the PLACEMENT parameter
> > > to the redefined figure environment?
> >
> > > I've tried some codes with PLACEMENT parameter, and then the figure(or
> > > table) appeared at the end of document.
> >
> > \makeatletter
> > \g@addto@macro\@floatboxreset{%
> > � \hangcaption
> > � \captiontitlefont{\sffamily}
> > � \centering}
> > \makeatother
> >
> > The macro \@floatboxreset is the last thing which is executed
> > before examining the floating environment's content. With that
> > code we supplement the definition of \@floatboxreset with the
> > desired commands.
> I've search the definition of \g@addto@macro, and then find it in the
> "source2e".
> As your codes, that would add those supplement commands into
> every float environment?

Yes.

Ciao
Enrico
0
Reply Enrico 12/20/2009 10:53:29 PM

Robin Fairbairns wrote:
> \let\tempfigure\figure
> 
> makes a "frozen" copy of \figure, which isn't changed by subsequent
> redefinition, so use that instead of the (corrected) \def.
> 
> (note the confusing fact that \let doesn't want braces round its
> second argument, like \def does.  this is the sort of thing you get,
> dabbling in tex internals (which i presume you don't often do, from
> the mistakes you've made).

On the other hands, \let allows you to use an equal sign. It's not
necessary, but I think it makes the code much more readable:

\let\tempfigure=\figure


-- 
You should make a point of trying every experience once -- except
incest and folk-dancing.
		-- A. Bax, "Farewell My Youth"

Eduardo M KALINOWSKI
eduardo@kalinowski.com.br
0
Reply Eduardo 12/21/2009 11:46:31 AM

On 12=D4=C221=C8=D5, =C9=CF=CE=E74=CA=B124=B7=D6, r...@cl.cam.ac.uk (Robin =
Fairbairns) wrote:
> In article <1080cf52-5e6f-4b78-9f6f-4d9aa19c7...@u18g2000pro.googlegroups=
..com>,
>  Rocky Zhang <rocky...@gmail.com> writes:
>
> >For example, I want to insert some commands such as
> >\centering
> >and some other commands come from ccaption package before the other
> >commands in the figure environment,
> >and no need to use a new environment name.
>
> >How to implement this effect?
> >I've tried the following codes, but it didn't work.
>
> >\def\tempfigure\figure
>
> i presume you mean
>
> \def\tempfigure{\figure}
>
> all (other) bets are off if you _didn't_ do that -- i can't imagine
> what the diagnostics might be like.
>
> >\renewcommand\figure
> > {\tempfigure
> >  \hangcaption
> >  \captiontitlefont{\sffamily}
> >  \centering}
>
> \tempfigure is "just" \figure, so the first thing \figure does is to
> call itself.  hence the diagnostic.
>
> \let\tempfigure\figure
>
> makes a "frozen" copy of \figure, which isn't changed by subsequent
> redefinition, so use that instead of the (corrected) \def.
>
> (note the confusing fact that \let doesn't want braces round its
> second argument, like \def does.  this is the sort of thing you get,
> dabbling in tex internals (which i presume you don't often do, from
> the mistakes you've made).
>
> >But, the following codes do work well:
> >\begin{figure}
> >  \hangcaption
> >  \captiontitlefont{\sffamily}
> >  \centering
> >....
> >\end{figure}
>
> of course.
> --
> Robin Fairbairns, Cambridge

Many thanks to everyone, I've got the particular solutions for figure
and table environments
as the following:

\makeatletter
\renewenvironment{figure}[2][\@empty]
 {\ifx\@empty#1\@float{figure}\else\@float{figure}[#1]\fi
  \hangcaption
  \captiontitlefont{\sffamily}
  \centering
  #2
 }
 {\end@float}
\renewenvironment{table}[2][]
 {\ifx\@empty#1\@float{table}\else\@float{table}[#1]\fi
  \captionnamefont{\hfill}
  \captiondelim{\hfill}
  \captionstyle{\\}
  \captiontitlefont{\sffamily}
  \centering
  #2
 }
 {\end@float}
\makeatother

Thanks again.
0
Reply Rocky 12/22/2009 2:56:10 AM

Rocky Zhang <rockyzhz@gmail.com> wrote:

> Many thanks to everyone, I've got the particular solutions for figure
> and table environments
> as the following:
> 
> \makeatletter
> \renewenvironment{figure}[2][\@empty]
>  {\ifx\@empty#1\@float{figure}\else\@float{figure}[#1]\fi

This test doesn't work: if you write \begin{figure}[], it fails.
The default placement for the figure environment is in the macro
\fps@figure (there is \fps@table for "table"); therefore something like

\renewenvironment{figure}[1][\fps@figure]
  {\edef\@temp{\noexpand\@float{figure}[#1]}\@temp
   ...}
  {...}

would be more robust (unless you are using babel for French). 
I would /never/ add an argument to such environment: this makes
the code not portable to other classes. I don't see any benefit
from writing

\begin{figure}[tp]{\small}

instead of

\begin{figure}[tp]
\small

(I guess that your idea is that the second argument contains 
declarations for the current figure or table environment).

Ciao
Enrico
0
Reply Enrico 12/22/2009 2:26:04 PM

On 12=D4=C222=C8=D5, =CF=C2=CE=E710=CA=B126=B7=D6, Enrico Gregorio <grego..=
..@math.unipd.it> wrote:
> Rocky Zhang <rocky...@gmail.com> wrote:
> > Many thanks to everyone, I've got the particular solutions for figure
> > and table environments
> > as the following:
>
> > \makeatletter
> > \renewenvironment{figure}[2][\@empty]
> >  {\ifx\@empty#1\@float{figure}\else\@float{figure}[#1]\fi
>

Thank you for your patient!

> This test doesn't work: if you write \begin{figure}[], it fails.
> The default placement for the figure environment is in the macro
> \fps@figure (there is \fps@table for "table"); therefore something like
Oh, I see. In fact, I've tried the command \fps@TYPE, and it didn't
work. thanks:-)
>
> \renewenvironment{figure}[1][\fps@figure]
>   {\edef\@temp{\noexpand\@float{figure}[#1]}\@temp

Here why not use \@float{figure}[#1] directly? Could you elaborate the
difference between them?

>    ...}
>   {...}
>
> would be more robust (unless you are using babel for French).
> I would /never/ add an argument to such environment: this makes
> the code not portable to other classes. I don't see any benefit
> from writing
>
> \begin{figure}[tp]{\small}
>
> instead of
>
> \begin{figure}[tp]
> \small
I've already understood your meaning, I will revise as your suggestion
immediately. But it seems that the latter form is also compatible with
my original redefinition.
>
> (I guess that your idea is that the second argument contains
> declarations for the current figure or table environment).
>
> Ciao
> Enrico

0
Reply Rocky 12/22/2009 4:34:04 PM

On 12=D4=C223=C8=D5, =C9=CF=CE=E712=CA=B134=B7=D6, Rocky Zhang <rocky...@gm=
ail.com> wrote:
> On 12=D4=C222=C8=D5, =CF=C2=CE=E710=CA=B126=B7=D6, Enrico Gregorio <grego=
....@math.unipd.it> wrote:
>
> > Rocky Zhang <rocky...@gmail.com> wrote:
> > > Many thanks to everyone, I've got the particular solutions for figure
> > > and table environments
> > > as the following:
>
> > > \makeatletter
> > > \renewenvironment{figure}[2][\@empty]
> > >  {\ifx\@empty#1\@float{figure}\else\@float{figure}[#1]\fi
>
> Thank you for your patient!
Sorry ,                     ~~~~~I mean patience.
>
> > This test doesn't work: if you write \begin{figure}[], it fails.
> > The default placement for the figure environment is in the macro
> > \fps@figure (there is \fps@table for "table"); therefore something like
>
> Oh, I see. In fact, I've tried the command \fps@TYPE, and it didn't
> work. thanks:-)
>
>
>
> > \renewenvironment{figure}[1][\fps@figure]
> >   {\edef\@temp{\noexpand\@float{figure}[#1]}\@temp
>
> Here why not use \@float{figure}[#1] directly? Could you elaborate the
> difference between them?
>
> >    ...}
> >   {...}
>
> > would be more robust (unless you are using babel for French).
> > I would /never/ add an argument to such environment: this makes
> > the code not portable to other classes. I don't see any benefit
> > from writing
>
> > \begin{figure}[tp]{\small}
>
> > instead of
>
> > \begin{figure}[tp]
> > \small
>
> I've already understood your meaning, I will revise as your suggestion
> immediately. But it seems that the latter form is also compatible with
> my original redefinition.
>
>
>
>
>
> > (I guess that your idea is that the second argument contains
> > declarations for the current figure or table environment).
>
> > Ciao
> > Enrico- =D2=FE=B2=D8=B1=BB=D2=FD=D3=C3=CE=C4=D7=D6 -
>
> - =CF=D4=CA=BE=D2=FD=D3=C3=B5=C4=CE=C4=D7=D6 -

0
Reply Rocky 12/22/2009 4:36:00 PM

Rocky Zhang <rockyzhz@gmail.com> wrote:

> On 12��22��, ���10�26�, Enrico Gregorio <grego...@math.unipd.it> wrote:
> > Rocky Zhang <rocky...@gmail.com> wrote:
> > > Many thanks to everyone, I've got the particular solutions for figure
> > > and table environments
> > > as the following:
> >
> > > \makeatletter
> > > \renewenvironment{figure}[2][\@empty]
> > >  {\ifx\@empty#1\@float{figure}\else\@float{figure}[#1]\fi
> >
> 
> Thank you for your patient!
> 
> > This test doesn't work: if you write \begin{figure}[], it fails.
> > The default placement for the figure environment is in the macro
> > \fps@figure (there is \fps@table for "table"); therefore something like
> Oh, I see. In fact, I've tried the command \fps@TYPE, and it didn't
> work. thanks:-)
> >
> > \renewenvironment{figure}[1][\fps@figure]
> >   {\edef\@temp{\noexpand\@float{figure}[#1]}\@temp
> 
> Here why not use \@float{figure}[#1] directly? Could you elaborate the
> difference between them?

Because the expansion of \@float needs to look at the actual characters
that form the optional argument, doing a "loop" on them.

With this \edef, TeX is presented with the token list

\@float{figure}[<expansion of #1>]

Assuming  \def\fps@figure{htp}, a call such as

\begin{figure}

would give

\@float{figure}[htp]

In the case the optional argument is specified, say

\begin{figure}[tp]

the \edef would really do nothing, but would present TeX the
list \@float{figure}[tp].

Actually this doesn't take care for an empty optional argument
either, as it should. :(

So I suggest you something else, again with \@floatboxreset:

\makeatletter
\def\zh@figure{figure}
\def\zh@table{table}
\g@addto@macro\@floatboxreset{%
  \ifx\@currenvir\zh@figure
    \hangcaption
  \fi
  \ifx\@currenvir\zh@table
    \captionnamefont{\hfill}%
    \captiondelim{\hfill}%
    \captionstyle{\\}%
  \fi
  \captiontitlefont{\sffamily}
  \centering
 }
\makeatother

The code in \@floatboxreset is executed at each call of \@float,
but with the conditional inside the code we can distinguish whether
the environment is figure or table and act differently: the macro
\@currenvir contains the current environment's name. Of course you
are not be calling \figure or \table directly, are you? :)

OTOH, with the caption package it's very easy to specify different
setting for figure and table captions:

\captionsetup[figure]{<setup>}
\captionsetup[table]{<setup>}

Ciao
Enrico
0
Reply Enrico 12/22/2009 5:09:00 PM

On 12=E6=9C=8823=E6=97=A5, =E4=B8=8A=E5=8D=881=E6=97=B609=E5=88=86, Enrico =
Gregorio <grego...@math.unipd.it> wrote:
> Rocky Zhang <rocky...@gmail.com> wrote:
> > On 12=C3=AF=C3=A522=C3=A9=C3=8D, =C3=AC=C3=A5=C3=AB 10=C3=A6=C2=B126=C3=
=A1=E2=80=A6, Enrico Gregorio <grego...@math.unipd.it> wrote:
> > > Rocky Zhang <rocky...@gmail.com> wrote:
> > > > Many thanks to everyone, I've got the particular solutions for figu=
re
> > > > and table environments
> > > > as the following:
>
> > > > \makeatletter
> > > > \renewenvironment{figure}[2][\@empty]
> > > > =C2=A0{\ifx\@empty#1\@float{figure}\else\@float{figure}[#1]\fi
>
> > Thank you for your patient!
>
> > > This test doesn't work: if you write \begin{figure}[], it fails.
> > > The default placement for the figure environment is in the macro
> > > \fps@figure (there is \fps@table for "table"); therefore something li=
ke
> > Oh, I see. In fact, I've tried the command \fps@TYPE, and it didn't
> > work. thanks:-)
>
> > > \renewenvironment{figure}[1][\fps@figure]
> > > =C2=A0 {\edef\@temp{\noexpand\@float{figure}[#1]}\@temp
>
> > Here why not use \@float{figure}[#1] directly? Could you elaborate the
> > difference between them?
>
> Because the expansion of \@float needs to look at the actual characters
> that form the optional argument, doing a "loop" on them.
>
> With this \edef, TeX is presented with the token list
>
> \@float{figure}[<expansion of #1>]
>
> Assuming =C2=A0\def\fps@figure{htp}, a call such as
>
> \begin{figure}
>
> would give
>
> \@float{figure}[htp]
>
> In the case the optional argument is specified, say
>
> \begin{figure}[tp]
>
> the \edef would really do nothing, but would present TeX the
> list \@float{figure}[tp].
>
> Actually this doesn't take care for an empty optional argument
> either, as it should. :(
>
> So I suggest you something else, again with \@floatboxreset:
>
> \makeatletter
> \def\zh@figure{figure}
> \def\zh@table{table}
> \g@addto@macro\@floatboxreset{%
> =C2=A0 \ifx\@currenvir\zh@figure
> =C2=A0 =C2=A0 \hangcaption
> =C2=A0 \fi
> =C2=A0 \ifx\@currenvir\zh@table
> =C2=A0 =C2=A0 \captionnamefont{\hfill}%
> =C2=A0 =C2=A0 \captiondelim{\hfill}%
> =C2=A0 =C2=A0 \captionstyle{\\}%
> =C2=A0 \fi
> =C2=A0 \captiontitlefont{\sffamily}
> =C2=A0 \centering
> =C2=A0}
> \makeatother
>
> The code in \@floatboxreset is executed at each call of \@float,
> but with the conditional inside the code we can distinguish whether
> the environment is figure or table and act differently: the macro
> \@currenvir contains the current environment's name. Of course you
> are not be calling \figure or \table directly, are you? :)
>
> OTOH, with the caption package it's very easy to specify different
> setting for figure and table captions:
>
> \captionsetup[figure]{<setup>}
> \captionsetup[table]{<setup>}
>
> Ciao
> Enrico- =E9=9A=90=E8=97=8F=E8=A2=AB=E5=BC=95=E7=94=A8=E6=96=87=E5=AD=97 -
>
> - =E6=98=BE=E7=A4=BA=E5=BC=95=E7=94=A8=E7=9A=84=E6=96=87=E5=AD=97 -

Thank you for your wanderful explain! :-)
0
Reply Rocky 12/24/2009 2:41:07 AM

15 Replies
184 Views

(page loaded in 1.024 seconds)


Reply: